Skip to content

The JSON view

Nicholas K. Dionysopoulos edited this page Feb 12, 2015 · 1 revision

The Json view class FOF30\View\DataView\Json is designed to create data-aware Views which result in downloadable JSON files.

JSON files can be used in Javascript as well as most major programming languages. Moreover, since the Json view supports the Hypertext Application Language (HAL) it can be used to create a RESTful application interface which can be easily used from a Javascript front-end.

This View class is simply an extension to the Raw view class. Everything described in the Raw view class still applies here. The Csv class adds a few features on top of what Raw can already do.

HAL support

Setting the $this->useHypermedia boolean property tells FOF whether it should generate application/json+hal documents with HAL support. The default is false, creating a plain JSON file with either a list of records (browse views) or an individual record (read views). You can set this in the constructor of your view class.

When HAL support is enabled, the MIME type reported is application/json+hal. The resulting document will contain the _links section with links to the pagination results for browse views. By default FOF does not include embedded documents (relations).

JSONP support

FOF supports JSONP out of the box for all Json views. You can pass the callback URL parameter with the name of the Javascript function you want to call. The only parameter passed to the callback function will be the generated JSON document.

Clone this wiki locally
You can’t perform that action at this time.