/** * Create JSON response * * Encodes and returns data to JSON. Content-Type header set to * 'application/json', and disables layouts and viewRenderer (if being * used). * * @param mixed $data * @param boolean $keepLayouts * @param boolean|array $keepLayouts * NOTE: if boolean, establish $keepLayouts to true|false * if array, admit params for Zend_Json::encode as enableJsonExprFinder=>true|false * if $keepLayouts and parmas for Zend_Json::encode are required * then, the array can contains a 'keepLayout'=>true|false * that will not be passed to Zend_Json::encode method but will be passed * to Zend_View_Helper_Json * @throws Zend_Controller_Action_Helper_Json * @return string */ public function encodeJson($data, $keepLayouts = false) { $jsonHelper = new Zend_View_Helper_Json(); $data = $jsonHelper->json($data, $keepLayouts); if (!$keepLayouts) { Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true); } return $data; }
/** * echo array to json * and set response type application/json * * @param unknown_type $return */ private function _encodeJson($return) { /** * @see Zend_View_Helper_Json */ require_once 'Zend/View/Helper/Json.php'; $jsonHelper = new Zend_View_Helper_Json(); $data = $jsonHelper->json($return); return $data; }
/** * Create JSON response * * Encodes and returns data to JSON. Content-Type header set to * 'application/json', and disables layouts and viewRenderer (if being * used). * * @param mixed $data * @param bool $keepLayouts * @return string */ public function encodeJson($data, $keepLayouts = false) { require_once 'Zend/View/Helper/Json.php'; $jsonHelper = new Zend_View_Helper_Json(); $data = $jsonHelper->json($data, $keepLayouts); if (!$keepLayouts) { require_once 'Zend/Controller/Action/HelperBroker.php'; Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true); } return $data; }