I have a controller setup that uses a whole bunch of different AjaxContent helpers.
My init() for the controller looks something like this:
$ajaxContext = $this->_helper->getHelper('AjaxContext');
$ajaxContext->addActionContext('index', 'html')
->addActionContext('compose', 'html')
->addActionContext('sent', 'html')
->addActionContext('recipients','html')
->addActionContext('inbox', 'html')
->addActionContext('sendsuccess','html')
->initContext();
At the end of the composeAction(), if a certain condition is met, the AJAX request should forward to sendsuccessAction().
Doing this with the standard _forward() method doesn’t seem to forward it as an AjaxContent request – the page wants to render using the standard view template.
Any ideas on how I can use _forward or some other redirect method but keep the request as an AJAX request so the proper action context fires?
Basically what’s happening is that the
initContext()method (which sets up the environment for an ajax response) only gets called for your first dispatched action, not the second.There’s a bunch of different ways around this.
First, to verify this is the issue, try calling
from your
sendsuccessAction. This will force the AjaxContext action helper to properly set up the viewRenderer again.Alternatively, you could move the call to
$ajaxContext->initContext()from theinit()method to thepreDispatch()method of your controller. This will cause it to run before each action is dispatched.