Skip to content

Instantly share code, notes, and snippets.

@ischenkodv
Created November 30, 2014 00:35
Show Gist options
  • Save ischenkodv/a3b6c5485437f46b6c04 to your computer and use it in GitHub Desktop.
Save ischenkodv/a3b6c5485437f46b6c04 to your computer and use it in GitHub Desktop.
Return JSON data from action of Joomla controller.
/**
* JSON response from controller's action.
*/
public function run( )
{
JFactory::getDocument()->setMimeEncoding( 'application/json' );
JResponse::setHeader('Content-Disposition','attachment;filename="progress-report-results.json"');
$data = array(
'foo' => 'bar'
);
echo json_encode( $data );
JFactory::getApplication()->close(); // or jexit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment