有没有办法从Zend Framework中的引导程序重定向浏览器? [英] Is there a way to redirect the browser from the bootstrap in Zend Framework?

查看:84
本文介绍了有没有办法从Zend Framework中的引导程序重定向浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要根据引导文件中的某些条件进行重定向。

在定义了前端控制器和路由之后就完成了。

我该怎么做? >
(我知道我可以简单地使用header('Location:....)。关键是我需要使用路由器来构建URL。

I need to redirect according to some conditions in the bootstrap file.
It is done AFTER the front controller and routes are defined.
How do I do that?
(I know I can simply use header('Location: ....) The point is I need to use the Router to build the URL.

推荐答案

一年多以后,我正在ZF编程,并且为您的问题找到了此解决方案
这是我在引导程序中的功能,用于确定用户的登录位置。

more than year later, i'm programming in ZF and I got this solution for your problem. Here is my function in bootstrap that determines where the user is logged on.

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap

{

protected $_front;

(...)

protected function _initViewController() 
{
    (...)

    $this->bootstrap('FrontController');
    $this->_front = $this->getResource('FrontController');

    (...)
}

protected function _initLogado()
{
    $router = $this->_front->getRouter();
    $req = new Zend_Controller_Request_Http();
    $router->route($req);
    $module = $req->getModuleName();

    $auth = Zend_Auth::getInstance();
    if ($auth->hasIdentity()) {
        $this->_view->logado = (array) $auth->getIdentity();
    } else {
        $this->_view->logado = NULL;
        if ($module == 'admin') {
            $response = new Zend_Controller_Response_Http();
            $response->setRedirect('/');
            $this->_front->setResponse($response);
        }
    }
}

}

这篇关于有没有办法从Zend Framework中的引导程序重定向浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆