« Return to Thread: Autoloading modules

Re: Autoloading modules

by dmitrybelyakov :: Rate this Message:

Reply to Author | View in Thread

Hello,

There is some more on the topic i discovered after tweaking it around: the problem seems to be because of default module actually being 'default' that makes Zend MVC treat it like an ordinary application folder and NOT like a module folder.

That's the reason why module's Bootstrap is ignored and global application Bootstrap is used. In other words your global application bootstrap must be under your default module folder. It seems a little strange to me, as i would prefer all my modules be treated the same way and have application Bootstrap hold al common things for all the application and module Bootstraps handle module-dependent configurations.

I found some topics here on the list addressing similar problem but no practical solution still.

I found two ways of handling such cases but they both just don't seem right to me and appear to be a little hacky.

So the first one is to create special _initAutoloader() method in global Bootstrap specially for the default module (with module name as a namspace):

    protected function _initAutoload()
    {

        $autoloader = new Zend_Application_Module_Autoloader(array(
            'namespace' => 'Modulename',
            'basePath'  =>  APPLICATION_PATH . '/modules/modulename'
        ));
        return $autoloader;
    }
   
I don't like the idea of treating my default module in 'special' way, i would rather prefer it treated regularly like all the other modules. But still it allows autoloading default module's resources.


The other approach is to tweak application config and point my controlerDirectory to default module's controllers directory and do not specify default module at all.

# controllers
resources.frontController.controllerDirectory = APPLICATION_PATH "/modules/modulename/controllers"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
#resources.frontController.defaultModule = "modulename"   <-- remove this

This allows to use both global application Bootstrap and default Module's bootstrap BUT seems to be a very much a hack.

So there's a lot of confusion here fore me and i would appreciate if someone could make this more clear.


Thank you.
Dmitry.

 « Return to Thread: Autoloading modules