Yii::app()->controller->action->id not working

Yii::app()->controller->id works fine when calling it from a view and from Controller.php

however

[b]

Yii::app()->controller->action->id[/b] works fine when calling it from a view but doesn’t work when calling from Controller.php. Yii::app()->controller->action returns null in Controller.php

why?

How you are using it?

beforeAction

afterAction

init

beforeRender

I am using it in the init() method of Controller.php

Actions are not yet initiated in the init function

http://www.yiiframework.com/doc/api/1.1/CController/#init-detail

Also,

http://www.yiiframework.com/doc/api/1.1/CController#getAction-detail

thanks

If you need, then you can use filters to check/set the data.

ok, thanks for the information. Does this mean that is not possible to retrieve the action in the Controller.php?

hello all,

I am using afterAction() inside modules controllers in yii1 , but its not getting working, how can I check and use it, any brief explanation will be appreciated.

Thanks sally

No, it means you cannot get that information before the controller i initialized (init()). What you can do is override the init() function in your controller, call the parent init function from there, and then you get the action id. Example code inside your controller:




function init() {

  parent::init(); // calling parent/Controller init function

  // your code below here:

}



Yii::app()->controller->id is not working in Iphone 11 OS13