Book Image

Yii Project Blueprints

By : Charles R. Portwood ll
Book Image

Yii Project Blueprints

By: Charles R. Portwood ll

Overview of this book

Table of Contents (15 chapters)
Yii Project Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Adding custom routes to a module


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:

  1. Start by creating a new file, routes.php, in protected/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',
    );

    Note

    This example is purely to illustrate how...