Zend framework Zend框架自动模块路由
我的zend框架结构如下:Zend framework Zend框架自动模块路由,zend-framework,Zend Framework,我的zend框架结构如下: application/ configs/ application.ini routes.php layouts/ scripts/ includes/ layout.phtml modules/ somemodule1/ controllers/ IndexController
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文件的情况下(在系统中添加新模块后)自动加载模块。有人能帮我吗?您想要实现的行为是来自Zend Framework的默认行为。试着这样做:
$moduleLoader = new Zend_Application_Module_Autoloader
(
array
(
'namespace' => '',
'basePath' => APPLICATION_PATH
)
);
不要忘记在控制器名称中使用模块前缀:Somemodule1\u IndexController。引导程序如何调用routes.php?主应用程序引导和模块引导类中有什么?