Mohammad Ali Akbari
Mohammad Ali Akbari

Reputation: 10395

DefaultController in Yii. Question of naming

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

Answers (3)

aslingga
aslingga

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

Tommy Bravo
Tommy Bravo

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

Sergi Juanola
Sergi Juanola

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

Related Questions