Module Routes

Please correct me if i am wrong and i can do this with Yii already without hacking the core files.

If i have a method called actionView() in the modules/moduleName/controllers/DefaultController.php and i access /moduleName/view/, yii thinks that i am looking for a ViewController file, which is not the best assumption in this case. In order to access that method from the default controller, i need to do /moduleName/default/view/ which is very ugly, i mean, why the “default” word should be in URL ? Wouldn’t be 10 times nicer, if we could name the default controller same name as the module and in this case, when something like /moduleName/view is requested Yii should look to see if there is a ViewController file, if not, then it should look for the file named ModuleNameController.php and if it finds it to return the actionView method from within that controller ?

I believe this is the way it should work, because it gives more flexibility and performance boost, because we don’t have to remap the default controller for each requested action .

What i am trying to get here, is a smooth way to get rid of the name "default" from the url when accessing

a module. I am aware that i can do this by hard coding the URL manager rules, but there has to be another way,

so that i don’t have to write tens of rules to achieve this.

I have a cms with over 20 modules and many of them have 3 or 4 sub-modules, if i write rules for each of the modules, the performance will decrease considerably .

Ideas ?

I think you can change the defaultController property in configuration to "default". By default it is "site", hence SiteController.

Check out the createController method in CWebApplication.php.

@jamesmoey, you miss the point here. Is not about the default controller of the app, but the default controller of a module

Somebody else ? :)

Try to use parameterized routes:

'rules' => array(

                '<module:\\w+>/<action:\\w+>' => '<module>/default/<action>',

		'<module:\\w+>/<submodule:\\w+>/<action:\\w+>' => '<module>/<submodule>/default/<action>',


Needs careful design, as these rules may not play nice with your existing routing rules.