如何在init()或yii中的constructor()方法中获取操作id和控制器id


How can i get action id and controller id in init() or constructor() method in yii

我想在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;