-- hobodave <[email protected]> wrote
(on Monday, 31 August 2009, 12:56 PM -0700):
> I'm struggling trying to get this working. 
> 
> I need to add a resourceType to all of my modules:
> 
> 'report' => array(
>     'path' => 'reports/',
>     'namespace' => 'Report'
> )
> 
> Is there a way to do this in a DRY fashion? Id rather not add a
> Bootstrap.php class for all of my modules. Can this be done just in a
> _initModules() method in application/Bootstrap.php? If so, how? The only way
> I can see to do it, is to iterate over the modules, which seems clunky as
> I'm sure something else in the bootstrap process is already doing that.

Well, if you don't use the Modules resource plugin, or if you have no
bootstraps in your modules, then nothing is doing that; besides, the
operation is cheap. :)

So, yes, iterate over all the modules registered in the front
controller, and initialize a Zend_Application_Module_Autoloader object
for each; on each of these, add your report resource:

    protected function _initModuleAutoloaders()
    {
        $this->bootstrap('FrontController');
        $front = $this->getResource('FrontController');

        foreach ($front->getControllerDirectory() as $module => $directory) {
            $module = ucfirst($module);
            $loader = new Zend_Application_Module_Autoloader(array(
                'namespace' => $module,
                'basePath'  => dirname($directory),
            ));
            $loader->addResourceType('report', 'reports', 'Report');
        }
    }

-- 
Matthew Weier O'Phinney
Project Lead            | [email protected]
Zend Framework          | http://framework.zend.com/

Reply via email to