0

我在控制器级别处理异常时遇到问题。基本上我有一个控制器说 FOO 控制器,abcAction 和另一个控制器 BOO 与 xyz 动作。现在我必须在 abc 中调用 xyz 并且我必须使用它的输出。在 abc 中,我们正在调用其他一些我们抛出异常的 api。在 abc 中,我们使用 try catch 处理这些异常,并且代码在没有重新渲染视图之后完美执行。空白页来了。

代码

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。

如何摆脱这个?有没有其他方法可以在其他动作中调用动作?

4

1 回答 1

1

For ZF1, the ActionStack action helper is the correct way to do it. The problem you have is that this will then run the dispatch loop again, and the error controller is part of that loop when an exception happens.

I suspect that you need to not add xyz to the actionstack if abc has thrown an exception.

As you originally tagged this question with zend-framework2, the Forward controller plugin is the way to do this in ZF2.

于 2013-03-07T07:59:19.673 回答