有没有办法从 Zend Framework 中的引导程序重定向浏览器? [英] Is there a way to redirect the browser from the bootstrap in Zend Framework?
本文介绍了有没有办法从 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屋!
查看全文