Tried different time points to get the controller, but it`s always null.
This is how I try to access it:
Yii::app()->controller
I tried to recieve it onEndRequest event and also in init(). Both resolves to null.
I need to do some session-based state handling inside component which depends on the controller at hand.
Page 1 of 1
How to get controller inside component
#2
Posted 17 November 2009 - 04:57 PM
The component must be loading before the controller does. Is this component set to autoload? Why do you need the controller called from the component? This is not common
http://php-thoughts.cubedwater.com - my bloggings about Yii
#3
Posted 17 November 2009 - 06:35 PM
jonah, on 17 November 2009 - 04:57 PM, said:
The component must be loading before the controller does. Is this component set to autoload? Why do you need the controller called from the component? This is not common
onEndRequest is certainly not before controller:)
Actually why is it that so uncommon? Even if we take authorization, this also depends on controller name.
In my case I delete search query when not in specific set of pages.
#4
Posted 17 November 2009 - 07:20 PM
onEndRequest() is a method of CApplication, not CComponent.. Putting onEndRequest() in a component won't do anything. Unless you mean you are calling the component in onEndRequest(). How is the component called?
http://php-thoughts.cubedwater.com - my bloggings about Yii
#6
Posted 18 November 2009 - 11:45 AM
yes I tried using getController and i registered component method as onendrequest handler. If you look in the code it resets app controller back to $oldcontroller, but $oldcontroller is NULL. why is this swap necessary?
#7
Posted 19 November 2009 - 08:05 AM
juhe, on 18 November 2009 - 11:45 AM, said:
yes I tried using getController and i registered component method as onendrequest handler. If you look in the code it resets app controller back to $oldcontroller, but $oldcontroller is NULL. why is this swap necessary?
The swap I believe your talking about is required in the cases where a component is used, and the controller needs to be the current controller. OnEndRequest there is no active controller so you should get null.
You probably want to override YiiApp:afterControllerAction()
nz
Share this topic:
Page 1 of 1

Help












