我需要根据引导文件中的某些条件进行重定向。
这是在定义前端 Controller 和路由之后完成的。
我该怎么做?
(我知道我可以简单地使用 header('Location: ....) 重点是我需要使用 Router 来构建 URL。
最佳答案
一年多后,我在 ZF 中编程,并为您的问题找到了这个解决方案。 这是我在 Bootstrap 中的函数,用于确定用户登录的位置。
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 - 有没有办法从 Zend Framework 的 Bootstrap 重定向浏览器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/926361/