默认模块中控制器的命名空间/前缀
在我的 zf 应用程序中,我有 3 个模块:
- 申请人
- 公司
- 管理
并且,在我的 application.ini 中,我选择了一个默认模块
resources.frontController.defaultModule = "applicant"
因此,一些控制器类的命名如下:
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
In my zf application I have 3 modules:
- applicant
- company
- admin
And, in my application.ini I've picked a default module
resources.frontController.defaultModule = "applicant"
So, some of controllers classes are named like:
class IndexController extends Zend_Controller_Action /* in Applicant Module */
class Company_IndexController extends Zend_Controller_Action
class Admin_IndexController extends Zend_Controller_Action
Since applicant is my default module, I don't need to use module name as prefix in class name.
How can I use the prefixed way to name classes in my default module?
I want to use these class names
class Applicant_IndexController extends Zend_Controller_Action
class Company_IndexController extends Zend_Controller_Action
class Admin_IndexController extends Zend_Controller_Action
but I'm getting this error:
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如您所注意到的,默认模块中的控制器名称不需要前缀(例如:
SomeController
),而非默认模块中的控制器需要前缀(例如:Admin_SomeController
)。在基于模块的应用程序中,我个人发现用模块名称为所有控制器添加前缀更加一致。此问题已作为问题提交并在显然在版本 1.5 中添加了前端控制器设置
prefixDefaultModule
。因此,在
application/configs/application.ini
中,您可以添加:resources.frontController.prefixDefaultModule = true
我一直在使用它,并且认为它很棒。 ;-)
As you note, controller names in the default module do not require prefixing (Ex:
SomeController
), while controllers in non-default modules require prefixing (Ex:Admin_SomeController
).In module-based app, I personally find it more consistent to prefix all controllers with the module name. This was filed as an issue and fixed in apparently in version 1.5 by adding a front controller setting
prefixDefaultModule
.So, in
application/configs/application.ini
, you could add:resources.frontController.prefixDefaultModule = true
I use it all the time and think it's great. ;-)
请参阅 ZF 文档:调度程序
您可以在 application.ini 中设置它......
或从其他任何地方设置:
See the ZF Documentation: The Dispatcher
You can set it in your application.ini ...
.. or from anywhere else with: