2012-03-29 9 views
0

$this->_forward()を使用して、同じコントローラ内の別のアクションに移動しようとしていますが、動作しません。私のコードは...Zend Framework _forwardが機能しない

class IndexController extends Zend_Controller_Action 
{ 
    public function indexAction() 
    { 
     $this->view->bodyCopy = "<p>Please select a file to upload.</p>"; 

     $form = new forms_UploadForm(); 

     if ($this->_request->isPost()) { 
      $formData = $this->_request->getPost(); 
      if ($form->isValid($formData)) { 
       $this->_forward('displayFileContent'); 
      } else { 
       $form->populate($formData); 
      } 
     } else { 
      $this->view->form = $form; 
     } 

    } 

    public function displayFileContentAction() 
    { 
     die("In displayFileContentAction"); 
    } 
} 

しかし私は私の死のメッセージを得ていません。 'Page not found'というエラーが表示されます。

私は実際にこの問題を抱えているので、助力をいただければ幸いです。

+0

行動のラクダは、すべてを上げます。 – RockyFord

答えて

3

フォワーディングはなぜですか?ただ

return $this->displayFileContentAction(); 
+0

これは、displayFileContentビューのビューではなく、インデックスアクションビューを表示します。 – user1300814

0

$this->_forward('displayFileContent'); 

を置き換え、コードを実行なぜあなたはZend Frameworkののルーティング・スタックを通過$this->_forward('displayFileContent')を呼び出すときに

 $this->_redirect('/Controller/displayFileContent'); 

//Your action 

    public function displayFileContentAction(){ 
    $this->_helper->viewRenderer->setNoRender(true); 
    $this->_helper->layout->disableLayout(); 
    die("In displayFileContentAction"); 


    } 
+0

私は$ this - > _ redirect( '/ Index/displayFileContent')を試しました。しかし、リクエストされたURLがこのサーバ上に見つからなかったというエラーが返ってくるだけです。 – user1300814

0

を試してみてくださいいけません。ルーティングは、存在しないアクション(つまり、大文字と小文字を区別しません)を検索します(displayfilecontent)。

ラクダの代わりにダッシュを使用して$this->_forward('display-file-content')に転送する必要があります。

あなたはその後、display-file-content.phtmlという名前のビューファイルを作成する必要がありますか、このアクションのために

1

をレンダリングビューを無効にするために、あなたのコードは次のようになります。

class IndexController extends Zend_Controller_Action 
{ 
    public function indexAction() 
    { 
     $this->view->bodyCopy = "<p>Please select a file to upload.</p>"; 

     $form = new forms_UploadForm(); 

     if ($this->_request->isPost()) { 
      $formData = $this->_request->getPost(); 
      if ($form->isValid($formData)) { 
       return $this->_forward('display-file-content'); 
      } else { 
       $form->populate($formData); 
      } 
     } else { 
      $this->view->form = $form; 
     } 

    } 

    public function displayFileContentAction() 
    { 
     die("In displayFileContentAction"); 
    } 
} 

注:

  • に転送しますリクエストしたアクションは$this->_forward('display-file-content')に転送する必要があります。キャメルの代わりにダッシュを使用してください。
  • return$this->_forward('display-file-content')を追加するか、現在のアクションが実行されてから、他のアクションに転送されます。
  • 他のアクションのビューを作成してdisplay-file-content.phtmlと呼び出すか、$this->_helper->viewRenderer->setNoRender(true); $this->_helper->layout->disableLayout(); を使用してこのアクションのビューを無効にする必要があります。
関連する問題