0

library/My/Utils/Utils.php にファイルを作成しました。ファイルの内容は次のとおりです。

class My_Utils_Utils{
    public function test(){
        $this->_redirect('login');   
    }
}

このクラスはレイアウトから呼び出されます。問題は、_redirect(); I get this error にあります: ページが正しくリダイレ​​クトされていません。私の質問は_redirect()、ZEND フレームワーク 1 で作成したクラスから関数を呼び出す方法です。前もって感謝します。

4

3 に答える 3

0

redirect()の代わりに使用し_redirect()ます。使用法は次のとおりです。

$this->redirect(<action>, <controller>, <module>, <param>);

あなたの場合$this->redirect('login');、トリックを行う必要があります。

于 2013-11-05T09:53:22.560 に答える
0

_redirect 関数は Zend_Controller_Action クラスによって提供されます。これは次の 2 つの方法で修正できます。

  1. 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();
  1. 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();
    
于 2013-11-05T10:19:38.157 に答える