/** * Responds to the request with JSON. * * @param array $var The array that should be JSON-encoded and returned to the browser. * @param array $options An array of options. * * The $options array can contain the following values: * * - `'expires'` - Sets the Expires header value (in seconds). Defaults to `false`, which prevents * the response from getting cached. If set to `null`, no Expires header will be set. * * @return null */ public function returnJson($var = array(), $options = array()) { // Set the 'application/json' Content-Type header JsonHelper::setJsonContentTypeHeader(); $options = array_merge(array('expires' => false), $options); // Set the Expires header if ($options['expires'] === false) { HeaderHelper::setNoCache(); } else { if ($options['expires']) { HeaderHelper::setExpires($options['expires']); } } // Output it into a buffer, in case TasksService wants to close the connection prematurely ob_start(); echo JsonHelper::encode($var); craft()->end(); }