Search code examples
phpzend-frameworkzend-framework-modules

Zend Framework loads only default module controllers


I've got two modules, default and admin. While ZF does load admin layout correctly, it always loads only default-module controllers and default-module views.

The path to controllers is specified in module.ini file for each module. I have also tried to specify it in application.ini like this:

admin.resources.frontController.controllerDirectory = APPLICATION_PATH "/modules/admin/controllers"

With no effect whatsoever. Any ideas where the problem might be? I really liked ZF before I started working with modules..


Solution

  • First you'll want to declare this in your application.ini

    resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
    resources.frontController.defaultModule = "default"
    resources.modules[] = ""
    

    Then, put this bit of code in your Bootstrap.php file

    public function _initAutoload()
    {
        // Each module needs to be registered... 
        $modules = array(
            'Admin',
            'Default',
            'Support',
        );
    
        foreach ($modules as $module) {
            $autoloader = new Zend_Application_Module_Autoloader(array(
                'namespace' => ucfirst($module),
                'basePath'  => APPLICATION_PATH . '/modules/' . strtolower($module),
            ));
        }
    
        return $autoloader;
    }
    

    You're modules directory will look like this

    modules/
        |-- admin
        |   |-- controllers
        |   `-- views
        |-- default
        |   |-- controllers
        |   |-- forms
        |   |-- models
        |   `-- views
        `-- support
            |-- controllers
            |-- forms
            |-- models
            `-- views
    

    This in essence will create three modules default, admin, and support

    BTW.... I think we all struggled with modules in ZF. It just takes time, then once it works, it works. Best of luck.