Reputation: 10395
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?
Upvotes: 0
Views: 1070
Reputation: 1409
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
Yii::import('application.modules.module1.controllers.DefaultController');
I believe that Yii was similar to Java in the design of package
and class
.
Upvotes: 0
Reputation: 532
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).
Upvotes: 1
Reputation: 6647
DefaultController
will simply be called when you call yoursite/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.
Upvotes: 1