How To Remove Cntroller Name From Url

Hi everyone.

In yii framework how i can remove or hide the module’s controller name from url.

I have url like this


'http'://localhost/yiiproject/admin/default/login/

I would like to be that url like this


'http'://localhost/yiiproject/admin/login/

Hi

You could use Urlmanager

http://www.yiiframework.com/doc/guide/1.1/en/topics.url

with rule




'admin/login' => 'admin/default/login/'

for example in protected/config/main.php file in bellow block add the specified rule


array(

    ......

    'components'=>array(

        ......

        'urlManager'=>array(

            'urlFormat'=>'path',

            'rules'=>array(

                'admin/login' => 'admin/default/login'

            ),

        ),

    ),

);

You can use the controllerMap in config/main.php.




'controllerMap' => array(

        'admin' => 'admin.controllers.DefaultController', 

                   //or 'application.modules.admin.controllers.DefaultController'

        'user' => 'path.to.user.defaultcontroller' 

        ....

    ),




But if you call ‘admin/login’ (or another action of the DefaultController) the module of the DefaultController will not be loaded / initialized.

You have to change the constructor of the DefaultController like this:





class DefaultController extends CController {


 /**

     * Have to assign the module in __construct

     * if loaded directly from controllerMap

     *

     * @param string $id

     * @param string $module

     */

    public function __construct($id, $module = null)

    {

        if (!isset($module))

              $module = Yii::app()->getModule('admin');


        parent::__construct($id, $module);

    }