Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 866
Sejanus Avatar asked Nov 27 '25 09:11

Sejanus


2 Answers

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.

like image 53
Shane Stillwell Avatar answered Nov 29 '25 23:11

Shane Stillwell


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[] = 
like image 39
Ololo Avatar answered Nov 30 '25 00:11

Ololo