Created
July 22, 2015 19:29
-
-
Save fullybaked/7379ba54a947a8ccd694 to your computer and use it in GitHub Desktop.
JSON out from views
This file contains 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
<?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