Providing your own URL rules at runtime
When you are developing an application with a pluggable module architecture, you most likely need to somehow inject your module-specific rules into an existing application.
Getting ready
Set up a new application using
yiic webapp.Add
.htaccess, shown in the official URL management guide to yourwebrootfolder.Uncomment the
urlManagersection inprotected/config/main.phpand add'showScriptName' => false.Generate the
pagemodule using Gii. You need to uncomment thegiisection undermodulesand set a password. Then, openhttp://localhost/giiin your browser.Don't forget to add your new module to the
moduleslist in your application configuration.
The Yii code generator is shown in the following screenshot:

How to do it...
Create
ModuleUrlManager.phpin yourprotected/componentsdirectory with the following code inside it:<?php class ModuleUrlManager { static function collectRules() { if(!empty(Yii::app()->modules)) { foreach(Yii...