本文介绍了在Front Controller插件Zend中重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将重定向(基于身份验证和其他各种状态)集中到前端控制器插件中.到目前为止,我已经尝试过:

I'm trying to centralise my redirects (based on authentication and various other states) into a front controller plugin. So far I've tried:

    $this->setRequest(new Zend_Controller_Request_Http('my_url'));

在插件的各个位置(例如,从routeStartup到dispatchLoopShutdown),以及:

at various points in the plugin (i.e. from routeStartup to dispatchLoopShutdown) and also:

    $this->setResponse(new Zend_Controller_Response_Http('my_url'));

任何人都可以在此方面提供一些帮助,或者向我指出教程的方向吗?

Can anyone offer some assistance on this, or point me in the direction of a tutorial?

推荐答案

如果您希望在用户未登录的情况下进行重定向,则dispatchLoopStartup()的第一个参数是请求对象的句柄.

If you are looking to redirect if the user is not logged it, the first parameter of dispatchLoopStartup() is a handle to the request object.

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.
    }
}

这篇关于在Front Controller插件Zend中重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 15:04