JsonView (class)

Class JsonView

A view class that is used for JSON responses.

It allows you to omit templates if you just need to emit JSON string as response.

In your controller, you could do the following:

$this->set(['posts' => $posts]);
$this->set('_serialize', true);

When the view is rendered, the $posts view variable will be serialized into JSON.

You can also set multiple view variables for serialization. This will create a top level object containing all the named view variables:

$this->set(compact('posts', 'users', 'stuff'));
$this