I normally append an encoded json object to the response body, however I now have a situation that warrants using the ContextSwitch action helper.
I have a Zend_Form that requires three different response contexts:
For each context I have 3 view scripts. Although the two html contexts could use the same view script, but I haven't figured out if this is possible.
The html context views work okay, but the json view is not being picked up. What is the best method to override the default json post callback behaviour or pass a custom encoded object to the response body?
Personally, I don't use "View" to generate JSON content.
In my init()
, I have something like this:
$ajaxContext = $this->_helper->getHelper('AjaxContext');
$ajaxContext->setAutoJsonSerialization(false)
->addActionContext('index', array('html', 'json'))
->initContext();
And In my indexAction()
:
if ( true === $this->isAjaxJson() ) {
$this->_helper->json(
array(
'response' => $myResponse,
'message' => $myMesage
)
);
return;
}
Hope this help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With