我在 library/My/Utils/Utils.php 中创建了一个文件。该文件的内容是:
class My_Utils_Utils{
    public function test(){
        $this->_redirect('login');   
    }
}
此类从布局中调用;问题出在_redirect();  我收到此错误:页面未正确重定向。我的问题是如何_redirect()从您在 ZEND 框架 1 中创建的类中调用该函数。提前致谢。
我在 library/My/Utils/Utils.php 中创建了一个文件。该文件的内容是:
class My_Utils_Utils{
    public function test(){
        $this->_redirect('login');   
    }
}
此类从布局中调用;问题出在_redirect();  我收到此错误:页面未正确重定向。我的问题是如何_redirect()从您在 ZEND 框架 1 中创建的类中调用该函数。提前致谢。
使用redirect()而不是_redirect(). 用法是:
$this->redirect(<action>, <controller>, <module>, <param>);
在你的情况下$this->redirect('login');应该做的伎俩。
您可以使用重定向器 action-helper,您可以通过以下方式静态获取HelperBroker:
// get the helper
$redirectHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
// call methods on the helper
$redirect->gotoUrl('/some/url');
但是应该注意,布局被认为是视图层的一部分。通常,任何导致重定向的检查都应该在请求调度周期的早期进行,通常在控制器或前端控制器插件中。
_redirect 函数由 Zend_Controller_Action 类提供。您可以通过两种方式解决此问题:
扩展 Zend_Controller_Action 并使用 _redirect
class My_Utils_Utils extends Zend_Controller_Action {
   public function test(){
    $this->_redirect('login');   
   }
}
在布局中:
     $request = Zend_Controller_Front::getInstance()->getRequest();
     $response = Zend_Controller_Front::getInstance()->getResponse()
     $util = new My_Utils_Utils($request, $response); // The constructor for Zend_Controller_Action required request and response params.
    $util->test();
使用 gotoUrl() 函数 Zend_Controller_Action_Helper_Redirector::gotoUrl()
 $redirector = new Zend_Controller_Action_Helper_Redirector();
 $redirector->gotoUrl('login');
 //in layout : 
 $util = new My_Utils_Utils();
 $util->test();