Skip to content

Pagebakers/JsonView

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

JsonView for CakePHP

Description

Renders the ‘result’ view variables as json, with support for JsonP

Installation

  • 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

Usage

  • 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'));
}

About

A json view for Cakephp

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages