Skip to content

Instantly share code, notes, and snippets.

@fullybaked
Created July 22, 2015 19:29
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 fullybaked/7379ba54a947a8ccd694 to your computer and use it in GitHub Desktop.
Save fullybaked/7379ba54a947a8ccd694 to your computer and use it in GitHub Desktop.
JSON out from views
<?php
// data controller
public function get_data()
{
$data = [
'item' => $this->getDataFromSomewhere(),
'min' => 0,
'max' => 10
];
$this->set(compact('data'));
$this->set('_serialize', ['data']);
}
// routes
Router::extensions(['json']);
// get request to endpoint
curl my.domain.tld/data/get_data.json
// output
{
data: {
item: 10,
min: 0,
max: 10
}
}
// expected
{
item: 10,
min: 0,
max: 10
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment