February 21, 2011, 8:13pm
Hi. I’ve found out a little unexpected code behaviour and I’m wondering what you guys know about it.
I have a default controller, e.g. PageController; it has several actions, e.g. actionIndex (default), actionOther.
http://mysite/ - calls actionIndex at PageController which is expectable
http://mysite/page/other - calls actionOther which too is expectable
http://mysite/other cannot be resolved which is unexpectable.
What is expectable - is trying to find "actionOther" in default controller.
In order for “
http://mysite/other” to search PageController for actionOther, you need to add the following rule to the ‘urlManager’ component in the main config file:
or you can make it specific to ‘other’
Go here to learn more.
February 22, 2011, 7:56am
Yes, CUrlManager can help. But why not make this work by default?
February 22, 2011, 8:30am
That’s a design decision. Yii always has to find the controller, that’s responsible for the current request. So your route can either contain:
controllerID (default action of that controller is used)
‘’ (empty, meaning the default controller is used)
So if case 2. could be an actionID also, how should Yii know, what you’re talking about? (controllerID or actionID). Resolving the right controller in this case would be too expensive. Not to mention, how would you handle a conflict in that case?
February 22, 2011, 11:05am
But yii resolves conflicts of controllers and modules, doesn’t it?
If route cannot be resolved yii could try the first word as an action of default controller.
February 22, 2011, 11:22am
The fact is that Yii works differently.
Just fix it with urlManager and that’s all. The change you propose alter the logic of url resolving:
The logic is module/controller/view in that order
The module can be omitted for default controller.
If yii should find for default action in default controller if there is no controller specified, modules should be expected to resolve stuff like:
module/action as an action of the default controller in module.
February 22, 2011, 11:59am
The default controller is not so very default after all. That’s not right or is it?