我尝试使用模块结构构建我的应用程序,并阅读了很多解决方案(我认为最好的解决方案是http://offshootinc.com/blog/2011/02/11/modul-bootstrapping-in-zend -framework/comment-page-1/)但我遇到了一些问题,因为当我尝试为博客模块设置不同的默认控制器和操作时,Blog_Bootstrap_Initializer 中的代码如下:
protected function _initDefaultController(){
$front = $this->getBootstrap()->getResource('frontcontroller');
$front->setDefaultAction('index');
$front->setDefaultControllerName('Auth');
print "INITIALIZING Blog";
}
执行该方法是因为屏幕上显示了 INITIALIZING Blog 但代码无效。同样的情况是当我尝试在 application/modules/blog/configs/module.ini 中设置
resources.frontController.defaultControllerName = 'Auth'
resources.frontController.defaultAction = 'login'
或者
blog.resources.frontController.defaultControllerName = 'Auth'
blog.resources.frontController.defaultAction = 'login'
应用程序.ini
[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "FA"
autoloadernamespaces[] = 'SilverCms'
autoloadernamespaces[] = 'FA'
autoloadernamespaces[] = 'Twitter'
; FrontController
; module enable
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.params.displayExceptions = 0
; default controller, action and module
resources.frontController.params.useDefaultControllerAlways = false
resources.frontController.params.prefixDefaultModule = false
resources.frontController.defaultModule = 'default'
resources.modules[] = ''
;resources.frontController.defaultControllerName = 'Index'
;resources.frontController.defaultAction = 'index'
; language plugin enable
resources.frontController.plugins.Language = SilverCms_Controller_Plugin_Language
; module plugin enable
;resources.frontController.plugins.ActiveModule = SilverCms_Controller_Plugin_ActiveModule
resources.frontController.baseurl = /zftest/public/
; Locale
resources.locale.default = "en_US"
resources.locale.force = false
; Translate
resources.translate.adapter = "Tmx"
resources.translate.data = APPLICATION_PATH "/modules"
resources.translate.locale = "auto"
resources.translate.disableNotices = true
resources.translate.scan = directory
;cahce
cache.enable = false
; Routes
resources.router.routes.module.type = Zend_Controller_Router_Route_Module
resources.router.routes.module.abstract = On
resources.router.routes.language.type = Zend_Controller_Router_Route
resources.router.routes.language.route = ":language"
resources.router.routes.language.reqs.language = "^[a-z]{2}$"
resources.router.routes.language.defaults.language = "en"
resources.router.routes.default.type = Zend_Controller_Router_Route_Chain
resources.router.routes.default.chain = "language,module"
resources.router.routes.login.route = ':language/login/'
resources.router.routes.login.defaults.controller = 'Auth'
resources.router.routes.login.defaults.action = 'login'
; View
resources.view.helperPath.View_Helper = APPLICATION_PATH "/modules/default/views/helpers"
主引导程序
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initPlugins()
{
$this->bootstrap('frontController');
$front = Zend_Controller_Front::getInstance();
$front->setControllerDirectory(array(
'default' => APPLICATION_PATH .'/modules/default/controllers',
'blog' => APPLICATION_PATH .'/modules/blog/controllers',
'billing' => APPLICATION_PATH .'/modules/billing/controllers',
));
$front->registerPlugin(new SilverCms_Controller_Plugin_ActiveModule());
return $front;
}
protected function _initHelpers(){
Zend_Controller_Action_HelperBroker::addPrefix('SilverCms_Controller_Action_Helper');
}
}
模块中的主引导文件
class Blog_Bootstrap extends SilverCms_Application_Module_Bootstrap
{
}
模块中的配置文件(module.ini)
[production]
; uruchomienie domyslnego kontrolera gdy nie zostanie podany zaden inny
blog.resources.layout.layout = "blog"
blog.resources.layout.layoutPath = APPLICATION_PATH"/modules/blog/views/layouts/scripts"
blog.resources.frontController.defaultControllerName = 'Test'
blog.resources.frontController.defaultAction = 'test'
[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
我究竟做错了什么?