diff -r 5b37998e522e -r 162c1de6545a web/lib/Zend/View/Helper/Json.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/lib/Zend/View/Helper/Json.php Fri Mar 11 15:05:35 2011 +0100 @@ -0,0 +1,80 @@ +true|false + * this array can contains a 'keepLayout'=>true|false + * that will not be passed to Zend_Json::encode method but will be used here + * @return string|void + */ + public function json($data, $keepLayouts = false) + { + $options = array(); + if (is_array($keepLayouts)) + { + $options = $keepLayouts; + $keepLayouts = (array_key_exists('keepLayouts', $keepLayouts)) + ? $keepLayouts['keepLayouts'] + : false; + unset($options['keepLayouts']); + } + + $data = Zend_Json::encode($data, null, $options); + if (!$keepLayouts) { + require_once 'Zend/Layout.php'; + $layout = Zend_Layout::getMvcInstance(); + if ($layout instanceof Zend_Layout) { + $layout->disableLayout(); + } + } + + $response = Zend_Controller_Front::getInstance()->getResponse(); + $response->setHeader('Content-Type', 'application/json', true); + return $data; + } +}