karunakar
karunakar

Reputation: 76

zend controller weird issue

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 ?

Upvotes: 0

Views: 230

Answers (1)

Rob Allen
Rob Allen

Reputation: 12778

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.

Upvotes: 1

Related Questions