While Yii will perform a lot of module routing for free, we have to add our routes to our CUrlManager
configuration in main.php
at protected/config/
in order for our module to have any custom routing. While it's easy to execute, this method does not keep our module and application configurations sufficiently separated. To get around this limitation in Yii, we need to modify the CMSUrlManager
class that we created in the previous chapter in order to retrieve custom module routes that we define. This enables us to write routes as part of our module rather than as part of our application. The steps are as follows:
Start by creating a new file,
routes.php
, inprotected/modules/dashboard/config/
, that contains the following. For this module, we'll define a custom route for our save actions to be loaded from:<?php return array( '/dashboard/<controller:\w+>/save' => '/dashboard/<controller>/save', );