XF 2.0 How to get current page controller name and action?

Siropu

Well-known member
Licensed customer
For example, in a non controller class? Or in a template?
Is there a way to do that?
 
I can't see anything that'll let you get it directly (the route match doesn't seem to be stored anywhere), but this works:
PHP:
\XF::app()->router()->routeToController(\XF::app()->request()->getRoutePath());

(The XF class is available in templates)

Liam
 
It's part of the AbstractReply object, but it's not likely to be directly exposed in most cases. You'd likely need to trigger some code somewhere where the reply object is available (and complete).
 
PHP:
\XF::app()->router()->routeToController(\XF::app()->request()->getRoutePath());
This indeed works. You just have to use the getController() method to get the controller name.
Thank you.
 
Back
Top Bottom