0

我的 zend 框架具有以下结构:

application/
    configs/
        application.ini
        routes.php
    layouts/
        scripts/
            includes/
            layout.phtml
    modules/
        somemodule1/
            controllers/
                IndexController.php
                ErrorController.php
            models/
            views/
                helpers/
                scripts/
                    error/
                        error.phtml
                    index/
                        index.phtml
            forms/
            Bootstrap.php
        somemodule2/
            controllers/
                IndexController.php
                ErrorController.php
            models/
            views/
                helpers/
                scripts/
                    error/
                        error.phtml
                    index/
                        index.phtml
            forms/
            Bootstrap.php

    Bootstrap.php
library/
    Zend/
    CustomClasses/
public/
    css/
    images/
    js/
    uploads/
    .htaccess
    index.php

我试图使其模块化。例如,我想像这样访问每个模块:domain.com/modulename/controller/action/someotherparams。如果我添加新模块,那么它应该会自动加载,而不会对路由类进行任何更改。我已经做的是:

**routes.php**

protected function _initAutoloadModules()
{
    $autoloader = new Zend_Application_Module_Autoloader(
        array(
            'namespace' => '',
            'basePath'  => APPLICATION_PATH . '/modules/somemodule1'
        ), 
        array(
            'namespace' => 'Admin',
            'basePath'  => APPLICATION_PATH . '/modules/somemodule2'
        )            
      );
    return $autoloader;
}

**application.ini** 

phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
includePaths.library = APPLICATION_PATH "/../library"
appnamespace = "Default"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
resources.frontController.defaultModule = "default"
resources.frontController.defaultController = "index"
resources.frontController.defaultAction = "index"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.layout.layout = "layout"
resources.modules = ""
resources.view[] =
resources.session.remember_me_seconds = 864000
resources.session.use_only_cookies = on
includePaths.models = APPLICATION_PATH "/models/"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"

但实际上它并没有按照我想要的方式工作。因为我不能在不更改 routes.php 文件的情况下使模块自动加载(在新模块添加到系统之后)。那么有人可以帮我吗?

4

1 回答 1

1

您想要实现的行为是 Zend Framework 的默认行为。试试这种方式:

 $moduleLoader = new Zend_Application_Module_Autoloader
    (
            array
            (
                'namespace' => '',
                'basePath' => APPLICATION_PATH
            )
        );

不要忘记在控制器名称中使用模块前缀:Somemodule1_IndexController。

于 2012-11-21T08:23:40.530 回答