Пример #1
0
 /**
  * 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->direct($data, $keepLayouts);
     if (!$keepLayouts) {
         \Zend\Controller\Action\HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true);
     }
     return $data;
 }
Пример #2
0
 /**
  * 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->direct($data, $keepLayouts);
     if (!$keepLayouts) {
         $this->getBroker()->load('viewRenderer')->setNoRender(true);
     }
     return $data;
 }