Home » Php » php – How can I get the current action in Zend Framework?

php – How can I get the current action in Zend Framework?

Posted by: admin April 23, 2020 Leave a comment

Questions:

I have a plugin in my Zend Framework application that checks login status after every request, and reroutes the user to the login action if their session is invalid or expired. I would like to cache the previous request action so that, after a successful login attempt, I can redirect them back to their previous request.

I have found the documentation on the setActionController() method, but I can’t find anything on a “getActionController()” method. Does one exist? If so, does anyone have any information they could link me to on it? If not, what’s the best way to achieve my goal?

How to&Answers:

In the default routing, both the controller and the action are always passed along with the request.

$controller = $this->getRequest()->getControllerName();
$action = $this->getRequest()->getActionName();

Answer:

If you are not in controller, use:

Zend_Controller_Front::getInstance()->getRequest()->getControllerName();
Zend_Controller_Front::getInstance()->getRequest()->getActionName();