0

我有處理控制器級別異常的問題。基本上我有一個控制器說FOO控制器,abcAction和另一個控制器BOO與xyz行動。現在我必須在abc中調用xyz,並且必須使用該輸出。在abc中,我們正在調用其他一些我們拋出Exception的API。在abc中,我們正在使用try catch處理這些excptions,並且代碼在執行完後不會改變視圖。空白頁面即將到來。zend控制器奇怪的問題

代碼

class FooController extends Zend_Controller_Action { 
    function abcAction(){ 
     //some code here 
     //no based on the parameters we are calling other action 
     $view = new Zend_View();  
     try{ 
      $view->action('xyz','Boo','',$params); 
     }catch(Exception $e){ 
      //handling exception 
     } 

    } 
} 

class BooController extends Zend_Controller_Action { 
    function xyzAction(){ 
     //some code here 
     //calling other api where we are throwing exception if some conditions are not met and normally my error controller will handle it. 
    } 
} 

每當我們被拋出異常,我們正在空白頁。所以我用$ this - > _ helper-> actionStack() 替換了該視圖對象,現在它正在渲染錯誤控制器phtml和我的abcaction phtml。

如何擺脫這個?有沒有其他方法可以在其他操作中調用操作?

回答

1

對於ZF1,ActionStack動作助手是正確的做法。您遇到的問題是,這將再次運行調度循環,並且發生異常時,錯誤控制器是該循環的一部分。

我懷疑如果abc引發異常,您不需要將xyz添加到操作堆棧。

正如你最初用zend-framework2標記了這個問題,Forward控制器插件是在ZF2中做到這一點的方法。

+0

我得到致命錯誤。方法「轉發」不存在,並沒有被困在__call()中。目前我們正在使用zend 1.6。 – karunakar 2013-03-07 09:40:46

+0

一旦xyz被拋出異常我正在處理它之後,我必須執行一些代碼,然後我必須呈現abc phtml文件。在這裏我面臨着問題。以及abc phtml。我的errorcontroller phtml文件也渲染..如何我可以從調度循環中刪除此execptions? – karunakar 2013-03-07 11:25:06

+0

如果您沒有將異常泄漏出操作方法,我不知道調度循環如何知道它已經發生。 – 2013-03-07 12:11:08