我正在尝试将我的重定向(基于身份验证和其他各种状态)集中到一个前端 Controller 插件中。到目前为止,我已经尝试过:
$this->setRequest(new Zend_Controller_Request_Http('my_url'));
在插件的各个点(即从 routeStartup 到 dispatchLoopShutdown)以及:
$this->setResponse(new Zend_Controller_Response_Http('my_url'));
任何人都可以为此提供一些帮助,或者为我指明教程的方向?
最佳答案
如果您希望在用户未登录的情况下进行重定向,dispatchLoopStartup() 的第一个参数是请求对象的句柄。
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
{
if(!Zend_Auth::getInstance()->hasIdentity())
{
$request->setControllerName('auth');
$request->setActionName('login');
// Set the module if you need to as well.
}
}
关于zend-framework - 在前端 Controller 插件 Zend 中重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2357732/