Skip to content

Instantly share code, notes, and snippets.

@proweb proweb/json.php
Created Aug 14, 2013

What would you like to do?
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.