本文介绍了在 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 中重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-30 08:52