Search code examples
controlleryiiurl-rewritingslug

Yii get url part from controller


I have URL rule like this:

'urlManager'=>array(
    'urlFormat'=>'path',
    'rules'=>array(
        '' => 'site/index',
        '<controller:pages>/<slug>' => '<controller>/inPage',
    ),
    'showScriptName'=>false,
),

In action I can get slug like argument

public function actionInPage($slug)
{
    echo$slug;
}

But how can I get that parameter from main controller (protected/components/controller.php) or in controller view?


Solution

  • Try following way framework recommended.

    Yii::app()->request->getParam('slug');