0

i have a problem with handling exception in controller level. basically i have one controller say FOO controller , abcAction and another controller BOO with xyz action. now i have to call xyz inside abc and i have to use the output of that . in abc we are calling some other api which we throws Exception. in abc we are handling those excptions using try catch and code is executing perfectly after that it is not renedring the view . blank page is coming.

code

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.
    }
}

whenever we are throwing exception we are getting blank page. so i replaced that view object with $this->_helper->actionStack() now it is rendering error controller phtml and my abcaction phtml.

how to get rid of this ? is there any other way to call action inside other action ?

Rob Allen
  • 12,643
  • 1
  • 40
  • 49
karunakar
  • 76
  • 7

1 Answers1

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.

Rob Allen
  • 12,643
  • 1
  • 40
  • 49
  • i am getting below fatal error .Method "forward" does not exist and was not trapped in __call() . currently we are using zend 1.6. – karunakar Mar 07 '13 at 09:40
  • once xyz is thrown exception i am handling it correctly after that i have to execute some code then i have to render abc phtml file .here i am facing problem . along with abc phtml . my errorcontroller phtml files also rendering..how i can remove this execptions from dispatch loop ? – karunakar Mar 07 '13 at 11:25
  • If you are not leaking the exception out of the action method, I have no idea how the dispatch loop knows that it has occurred. – Rob Allen Mar 07 '13 at 12:11