Created
August 14, 2013 07:50
-
-
Save proweb/6228815 to your computer and use it in GitHub Desktop.
Best way for JSON output in Joomla controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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