2
votes

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..

4

4 Answers

7
votes

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.

4
votes

You have not to provide path to the controllers for each module. Just add the following directive into the application.ini:

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

To get access to the resources of your modules, i.e., forms, models, plugins etc; you need to add in a Bootstrap class for the module, in the root directory of the module. Have a look at the sample one below. Just by having that there, you can use the module's resources. Feel free to expand on that as your needs dictate.

<?php

class User_Bootstrap extends Zend_Application_Module_Bootstrap
{

}
0
votes