Hi all,
I need to create some webservices that will be called by either ajax calls from within our site or API calls coming from another server, and will reply with a JSON.
Is there an established best practice?
Digging in the code i found two different ways to do that:
if( $this->_getParam(‘sendNow’, true) )
{
return $this->_helper->json($data);
}
else
{
$this->_helper->viewRenderer->setNoRender(true);
$data = Zend_Json::encode($data);
$this->getResponse()->setBody($data);
}
I assume the difference must be in how the dispatchment loop will proceed after the generation of the JSON but I’m not sure - do you know?
Please don’t use ZF1 for new development work - it is unmaintained and abandoned since 2 years. https://framework.zend.com/blog/2016-06-28-zf1-eol.html
We are aware of that - but Social Engine is a quite robust and independently maintained platform. Any hint regarding the specific topic?
Your current usage is too complicated. You can simplify the code:
$sendNow = $this->_getParam('sendNow', true);
return $this->_helper->json($data, $sendNow);
And the rest is done by the helper.
All parameters are documented here: Action Helpers - JSON
Look also in the code of the helper.
Social Engine is a quite robust and independently maintained platform
That does not change the fact that the underlying framework is abandoned and unmaintained.
That’s what makes me even more grateful for the help I can get - as I said, I don’t have a say in the basic decision.
Version 2 of ZF was released on 6 September 2012. With this date, the version 1 should be supported for a maximum of 24 months. But at the end it was 48 months. The end of life was on 28 September 2016.
So please keep in mind, that it has been a long time since most of us have actively worked with the version 1. And we must not forget the current and new versions, which also need to get support.
The result of this: The support is very limited or not available at this point.