2009年3月2日星期一

Re: [fw-mvc] Proper use of Zend_Loader_Autoloader_Resource

-- Cristian Bichis <contact@zftutorials.com> wrote
(on Monday, 02 March 2009, 04:55 PM +0200):
> I got one more question. See below.
> Matthew Weier O'Phinney wrote:
> > -- Cristian Bichis <contact@zftutorials.com> wrote
> > Resource autoloading is different. It would be handled in one of two
> > places: an initializer in your bootstrap, or via the "modules" bootstrap
> > resource. This latter will (eventually) initialize a
> > Zend_Application_Module_Autoloader instance (this is a concrete instance
> > of Zend_Loader_Autoloader_Resource that has resources defined per the
> > recommended directory structure) per module in your application, and, if
> > a bootstrap class is available for that module, register it with that
> > bootstrap.
> >
> > I say eventually, as neither Ben nor I have put together this last bit
> > of functionality in the Modules resource yet.
> >
> Ok, so using code like this under bootstrap would be quite a standard
> way ? No other way to simplify the code mroe than below:

Please remember that Zend_Application is yet to be approved, and that
the prototype is under active development. For right now, the below is
(with modifications) how you would go about doing things; however, with
the final version of Zend_Application, it will likely be much easier.

> protected function _initResources()
> {
> $this->bootstrapFrontController();
> $loaders = array();
> foreach ($this->front->getControllerDirectory() as $module
> => $dir)
> {
> $loaders[$module] = new Zend_Application_Module_Autoloader(
> array(
> 'namespace' => ucfirst($module).'_',
> 'basePath' => dirname($dir),
> ) );
> $loaders[$module]->addResourceType('Model',
> 'models', 'Model');

The above line is unnecessary -- Zend_Application_Module_Autoloader
already defines the 'Model' resource.

> }
> }

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

没有评论: