Cakephp JsonView

I am using the new CakePHP 2.1 and would like to use JsonView to make the controller respond to the ajax request created by client-side jQuery. However, this should be done automatically using JsonView as per the documentation.

http://book.cakephp.org/2.0/en/views/json-and-xml-views.html

I added this line to the routes.php file

Router::parseExtensions('json');

And in my controller I have

 $this->RequestHandler->setContent('json', 'application/json' ); $bookings = $this->Bookings->find('all'); $this->set('bookings', $bookings); $this->set('_serialize', 'bookings'); 

Then the view should be outdated, but when I call it, it still serves a page that points to the missing view.

+7
source share
2 answers

Are you making a request with the header application / json?

Try making the request /controller/method.json. This should force a view. If this works, your headers will probably not be fixed.

+5
source

Do you /views/controller_name/json/action.ctp a view file inside /views/controller_name/json/action.ctp ?

+1
source

All Articles