php 如何在 Zend Framework 中获取当前操作?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/2784315/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I get the current action in Zend Framework?
提问by Daniel Ingraham
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.
我的 Zend Framework 应用程序中有一个插件,可以在每次请求后检查登录状态,如果会话无效或过期,则将用户重新路由到登录操作。我想缓存先前的请求操作,以便在成功登录尝试后,我可以将它们重定向回先前的请求。
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?
我找到了有关 setActionController() 方法的文档,但在“getActionController()”方法中找不到任何内容。一个存在吗?如果是这样,有没有人有任何可以将我链接到的信息?如果没有,实现我的目标的最佳方法是什么?
回答by nuqqsa
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();
回答by faramka
If you are not in controller, use:
如果您不在控制器中,请使用:
Zend_Controller_Front::getInstance()->getRequest()->getControllerName(); Zend_Controller_Front::getInstance()->getRequest()->getActionName();

