2009年4月8日星期三

Re: [fw-mvc] Autoloading module resources with 1.8 Preview

-- Cristian Bichis <contact@zftutorials.com> wrote
(on Wednesday, 08 April 2009, 09:37 PM +0300):
> I am using modular structure on ZF apps. I started to use
> Zend_Application and autoloader now couple of weeks.
>
> I was auto-loading module resources using this into an _initAutoloader()
>
> foreach ($this->frontController->getControllerDirectory() as
> $module => $dir)
> {
> $loaders[$module] = new Zend_Application_Module_Autoloader(
> array(
> 'namespace' => ucfirst($module).'_',
> 'basePath' => dirname($dir),
> ) );
> }
>
> Now, when 1.8 Preview was released i noticed i can't auto-load the
> modules resources,
>
> So:
>
> $acl = new 'MyModule_Model_Acl($auth);
>
> Fatal error: Class 'MyModule_Model_Acl' not found in
> D:\_Work\site\application\Bootstrap.php on line 154
>
> This is failing...
>
> How i am gonna auto-load resources for modules with or without their own
> module bootstrapper ?

Two things:

* First, extend Zend_Application_Module_Bootstrap in your module
bootstraps. Part of instantiation includes registering a module
autoloader for that module.

* Second, use the Modules resource plugin with your application
bootstrap. This will search through your module directories for
bootstraps and initialize them if found.

I'll be getting a full example up soon to make this more clear.

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

没有评论: