Skip to content

Instantly share code, notes, and snippets.

@proweb
Created August 14, 2013 07:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save proweb/6228815 to your computer and use it in GitHub Desktop.
Save proweb/6228815 to your computer and use it in GitHub Desktop.
Best way for JSON output in Joomla controller
class MyController extends JController
{
function someTask()
{
// Get the application object.
$app = JFactory::getApplication();
// Get the model.
$model = $this->getModel('MyModel');
// Get the data from the model.
$data = $model->getData();
// Check for errors.
if ($model->getError()) {
// Do something.
}
// Echo the data as JSON.
echo json_encode($data);
// Close the application.
$app->close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment