Migrate JsonView to CakePHP 2

While working on the migration of a Cake1.x project to Cake2, I faced a problem with the JsonView plugin of Pagebakers. Instead of being catched by the JsonView View, it just printed out the plain old html error of a missing view.

So what changed?

The variable “$this->view” which was used in Cake1 was replaced by $this->viewClass in Cake2. This was the number one cause of the problems.

Other cause, was the plugin not being loaded using the CakePlugin system:

CakePlugin::load('JsonView');

NOTE – Don’t forget to set the response type too!

// set content-type to application/json
$this->response>type('json', 'application/json');

Geef een reactie

Het e-mailadres wordt niet gepubliceerd. Verplichte velden zijn gemarkeerd met *