在我的 zf 应用程序中,我有 3 个模块:
而且,在我的 application.ini 中,我选择了一个默认模块
resources.frontController.defaultModule = "applicant"
因此,一些 Controller 类的名称如下:
class IndexController extends Zend_Controller_Action /* in Applicant Module */
class Company_IndexController extends Zend_Controller_Action
class Admin_IndexController extends Zend_Controller_Action
由于申请人是我的默认模块,我不需要在类名中使用模块名称作为前缀。
如何使用前缀方式在默认模块中命名类?
我想使用这些类名
class Applicant_IndexController extends Zend_Controller_Action
class Company_IndexController extends Zend_Controller_Action
class Admin_IndexController extends Zend_Controller_Action
但我收到此错误:
Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (error)' in ZendFramework-1.11.6/library/Zend/Controller/Dispatcher/Standard.php on line 248
最佳答案
如您所见,默认模块中的 Controller 名称不需要前缀(例如:SomeController
),而非默认模块中的 Controller 需要前缀(例如:Admin_SomeController
)。
在基于模块的应用程序中,我个人觉得在所有 Controller 前面加上模块名称更一致。这被归档为 an issue并固定在 apparently in version 1.5通过添加前端 Controller 设置 prefixDefaultModule
.
所以,在 application/configs/application.ini
,您可以添加:resources.frontController.prefixDefaultModule = true
我一直在使用它,并认为它很棒。 ;-)
关于zend-framework - 默认模块中 Controller 的命名空间/前缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6361974/