Renders the ‘result’ view variables as json, with support for JsonP
- Submodule:
git submodule add git://github.com/Pagebakers/JsonView.git path/to/app/plugins/json_view
git submodule init
git submodule update
- Clone:
git clone git://github.com/Pagebakers/JsonView.git path/to/app/plugins/json_view
- Download zip
- Download
http://github.com/Pagebakers/JsonView/zipball/master
- Extract to your
app/plugins
folder - Rename the extracted folder to
json_view
- The resulting structure should be
app/plugins/json_view/views/json.php
- The resulting structure should be
- Download
- To use it in every action of a controller, add it to your beforeFilter:
function beforeFilter() {
$this->view = 'JsonView.Json';
}
- or set it as a class variable
var $view = 'JsonView.Json'
- To initialize the view in whatever function you want it to be usable in
function action($id = NULL) {
$this->view = 'JsonView.Json';
}
- Then set json variables to the ‘result’
function action($id = NULL) {
$this->view = 'JsonView.Json';
$result = array('of', 'results', 'for', 'view');
$this->set(compact('result'));
}