Quantcast
Channel: Shani's Php CookBook
Viewing all articles
Browse latest Browse all 60

YII, How to get current controller name and action name

$
0
0
To get current controller name use this code :



<?php
$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


<?php
//inside beforeAction or afterAction
publicfunctionbeforeAction($action)
{
$actionId=$action->id;
...
?>



or just elsewhere inside your controller


<?php
$actionId=$this->getAction()->getId();
?>


To get name of currently called controller action anywhere in the code you can use :




<?php

print CController::getAction()->id;


?>





Viewing all articles
Browse latest Browse all 60

Trending Articles