0

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?

3 Answers 3

1

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).

Sign up to request clarification or add additional context in comments.

7 Comments

when I call an action of another module it will cause duplicate class name error. this is exactly my question.
Maybe you could explain why you need to call an action from module (A) in the action of another module (B)? Or you could just change one the names of the controller classes (don't forget to changed the filename also) from one of the modules. Keep in mind, this will change the route of the changed controller from <modulename>/default to <modulename>/<newcontrollername>.
for example I need render latest news and latest product in homepage, I should import both module1/defaultController and module2/defaultController to use two action latestnews and latestproduct
I think, what you are trying to do, is meant to be done in a components (in a module if you want). A controller is mostly just meant for rendering full pages (or at least that's what I make of it).
please explain you last comment, I think it's what i want
|
1

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.