我想在init()方法或construct()方法中获取操作名称和控制器名称。例如,如果我调用create方法,我应该在init()或constructor()方法中获得create作为动作名称。在Yii有可能吗?请帮忙。
使用如下方法:
public function afterAction($action){
$result=$action->getid();
echo $result; // you will get the action name
echo Yii::app()->getController()->getId(); //get the controller name
}
或者简单地在init()中使用此代码
echo Yii::app()->controller->id;
echo Yii::app()->controller->action->id;