开发者

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 lik开发者_如何学Goe 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..


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.


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[] = 


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
{

}


http://zendframework.com/manual/1.11/en/zend.application.available-resources.html

See the Zend_Application_Resource_Frontcontroller section.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜