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

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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

#1 User is offline   oligalma 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 419
  • Joined: 07-April 12
  • Location:Spain

Posted 28 December 2014 - 12:55 AM

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

however

Yii::app()->controller->action->id
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?
0

#2 User is offline   PeRoChAk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 589
  • Joined: 26-November 10
  • Location:Sialkot, Pakistan

Posted 28 December 2014 - 01:28 AM

How you are using it?

beforeAction
afterAction
init
beforeRender
Cheers
PeRoChAk
Cheap Domain & Hosting - Web & App Design - Web Application Development

My Page
1

#3 User is offline   oligalma 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 419
  • Joined: 07-April 12
  • Location:Spain

Posted 28 December 2014 - 02:01 AM

View PostPeRoChAk, on 28 December 2014 - 01:28 AM, said:

How you are using it?

beforeAction
afterAction
init
beforeRender


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

#4 User is offline   PeRoChAk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 589
  • Joined: 26-November 10
  • Location:Sialkot, Pakistan

Posted 28 December 2014 - 07:18 AM

Actions are not yet initiated in the init function

http://www.yiiframew...er/#init-detail

Also,

http://www.yiiframew...etAction-detail



thanks
Cheers
PeRoChAk
Cheap Domain & Hosting - Web & App Design - Web Application Development

My Page
2

#5 User is offline   PeRoChAk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 589
  • Joined: 26-November 10
  • Location:Sialkot, Pakistan

Posted 28 December 2014 - 07:21 AM

If you need, then you can use filters to check/set the data.
Cheers
PeRoChAk
Cheap Domain & Hosting - Web & App Design - Web Application Development

My Page
0

#6 User is offline   oligalma 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 419
  • Joined: 07-April 12
  • Location:Spain

Posted 28 December 2014 - 07:33 AM

View PostPeRoChAk, on 28 December 2014 - 07:18 AM, said:

Actions are not yet initiated in the init function

http://www.yiiframew...er/#init-detail

Also,

http://www.yiiframew...etAction-detail



thanks


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

#7 User is offline   chiku 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 21-October 17

Posted 20 November 2017 - 02:39 AM

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
0

#8 User is offline   Paul G. 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 74
  • Joined: 24-April 09
  • Location:Tel Aviv, Israel

Posted 20 November 2017 - 06:56 AM

View Postoligalma, on 28 December 2014 - 07:33 AM, said:

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


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 fan from Norway
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users