2009年2月24日星期二

Re: [fw-mvc] Default autoloading directory

Ahh thanks, Was wondering how such feature was not implemented yet. Thanks for the update.

On Tue, Feb 24, 2009 at 2:39 PM, Matthew Weier O'Phinney <matthew@zend.com> wrote:
-- vadim gavrilov <vadimg88@gmail.com> wrote
(on Tuesday, 24 February 2009, 08:21 AM +0200):
> Does zend allows to define a directory that it will try to autoload a class
> from it when ever a new instance of that class is initiated? I mean if i create
> a class MasterController
>
> Then i do MasterController::Something() i assume zend will not find it unless
> it's located in the library of the zend core files?! correct me if i am wrong.
> In Yii framework you could set directories that the autoload will look for the
> classes if it didn't find them in the default autoload directory. So i could
> just do
> $config['autoload_directories'] = array(
> 'application.models.*',
>         'application.widget.*',
>         'application.components.*',
> )
>
> then if i have the file MasterController.php in the application/components/ it
> will successfully load that class since it's located in one of the autoload
> directories. So my questions is , Does ZF has something like this?

Currently, Zend_Loader::loadClass() allows you to provide a second
argument, a set of directories you wish to scan when loading that class.
Another class, Zend_Loader_PluginLoader, can also be used, and allows
you to specify the class by a short name, to which a class prefix will
be added.

In 1.8, we are introducing Zend_Loader_Autoloader, and a "Resource"
variant. The main Autoloader class is a namespaced autoloader for
library classes. The second operates much more like what you're
describing, and allows you to specify a base directory under which all
classes have a common prefix, but under which the classes may not have a
1:1 correspondence with the actual file name. A variant on it,
Zend_Application_Module_Autoloader, comes with a set of resource
mappings that mirror the recommended project structure.

Zend_Loader_Autoloader and its related classes are currently in the
incubator, and will be promoted to trunk in the next few weeks.

--
Matthew Weier O'Phinney
Software Architect       | matthew@zend.com
Zend Framework           | http://framework.zend.com/




--
Vincent Gabriel.
Lead Developer, Senior Support.
Zend Certified Engineer.




没有评论: