Skip to content

Instantly share code, notes, and snippets.

@Zegnat
Created April 13, 2016 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zegnat/c9224e81098e68079f08e670a93a84ed to your computer and use it in GitHub Desktop.
Save Zegnat/c9224e81098e68079f08e670a93a84ed to your computer and use it in GitHub Desktop.
/**
* Send JSON encoded data to the browser and end all further processing.
* @method endWithJson
* @param array $data A data array.
* @throws InvalidArgumentException
* @return void
*/
private function endWithJson($data)
{
if (!is_array($data)) {
throw new \InvalidArgumentException('Method endWithJson requires a data array as argument.');
}
header('Content-type: application/json');
Yii::app()->end(json_encode($data));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment