Saturday, August 21, 2010

How to get current controller name and action name in Yii

To get current controller name/id inside your controller, or view
[cc lang='php']$controllerId = Yii::app()->controller->id;
//or
$controllerId = $this->getId();[/cc]
To get current action name/id being executed, if you are inside [cci]beforeAction()[/cci] or [cci]afterAction()[/cci], use the received CAction argument
[cc lang='php']
//inside beforeAction or afterAction
public function beforeAction($action)
{
$actionId = $action->id;
...
[/cc]
or just elsewhere inside your controller

[cc lang='php']$actionId = $this->getAction()->getId();[/cc]

1 comment:

  1. Great post. I was checking constantly this weblog and
    I am impressed! Very useful info specifically the last phase :) I
    take care of such information much. I used to
    be looking for this certain info for a long time. Thanks and good luck.

    ReplyDelete