How to get current controller name and action name in Yii

To get current controller name/id inside your controller, or view

1
2
3
$controllerId = Yii::app()->controller->id;
//or
$controllerId = $this->getId();

To get current action name/id being executed, if you are inside beforeAction() or afterAction(), use the received CAction argument

1
2
3
4
5
//inside beforeAction or afterAction
public function beforeAction($action)
{
  $actionId = $action->id;
...

or just elsewhere inside your controller

1
$actionId = $this->getAction()->getId();
Share

Related Posts

0 Responses to “How to get current controller name and action name in Yii”


  • No Comments

Leave a Reply