Yii 中的默认控制器。命名问题
我用 gii 为 Yii 框架创建了两个模块。每个模块都会创建自己的默认控制器类,称为“DefaultController”。
但我认为这是错误的,我相信它应该是“Module1_DefaultController”和“Module2_DefaultController”,就像Zend框架一样。
这是真的吗? 如果是这样,如何重命名控制器?
I create two modules for Yii framework with gii. Each module creates its own default controller class called "DefaultController".
But I think its wrong, I believe it should be "Module1_DefaultController" and "Module2_DefaultController" like Zend framework.
Is this true?
If so, how to rename the controllers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
除非您请求该模块执行某些操作,否则 Yii 不会包含具有 DefaultController 类的文件。这将防止重复的类名错误(我猜您怀疑),因为不能同时调用两个模块操作(这是设计使然)。
The file with the class DefaultController won't be included by Yii unless you request some action from that module. This will prevent a duplicate class name error (which I guess you suspect) because no two module actions can be called at the same time (this is by design).
当您调用
yoursite/yourmodule
时,将简单地调用DefaultController
。您无需更改其名称即可使其正常工作。不重命名控制器的原因是,当您访问您的站点/您的模块时,您实际上并没有调用控制器本身。您将转到模块根目录并获取默认控制器。这就是为什么你需要在配置中定义 模块:让 Yii 知道它需要寻找模块而不是控制器。
当然,您可以在该模块内创建更多控制器。
DefaultController
will simply be called when you callyoursite/yourmodule
. You don't need to change its name to make it work.The reason to not to rename the controller is that you are not actually calling the controller itself when going to yoursite/yourmodule. You are going to the module root and getting the default controller. That's why you need to define the module inside config: to let Yii know it needs to look for a module instead of a controller.
Of course, you can create more controllers inside this module.
Yii 创建的 DefaultController 并没有错,因为当你从另一个模块或类导入它时,你会像 Java 中的包一样导入它。应该是这样的
我相信Yii在
package
和class
的设计上与Java类似。The DefaultController crated by Yii is not wrong because when you import it from another module or class you will import it likes package in Java. It should be like this
I believe that Yii was similar to Java in the design of
package
andclass
.