默认模块中控制器的命名空间/前缀(Namespace / Prefix of Controller in Default Module)

编程入门 行业动态 更新时间:2024-10-27 04:24:46
默认模块中控制器的命名空间/前缀(Namespace / Prefix of Controller in Default Module)

在我的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

最满意答案

如您所知,默认模块中的控制器名称不需要前缀(Ex: SomeController ),而非默认模块中的控制器需要前缀(例如: Admin_SomeController )。

在基于模块的应用程序中,我个人发现使用模块名称为所有控制器添加前缀更加一致。 这是作为一个问题提交的,并通过添加前端控制器设置prefixDefaultModule 显然在版本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. ;-)

更多推荐

本文发布于:2023-07-19 01:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1169647.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:前缀   控制器   模块   空间   Namespace

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!