O'Reilly logo

CakePHP 2 Application Cookbook by Jorge González, James Watts

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Processing Ajax requests

It's no secret that Ajax has revolutionized web development and helped developers build and deliver engaging applications which have a real-time feel to them.

In this recipe, we'll look at how easy it is to handle Ajax requests in CakePHP and give you an introduction to the possibilities at your fingertips.

Getting ready

For this recipe, we'll reuse the books database table from the previous chapter. We'll also need a view for our inventory_index(). action, so create a file named inventory_index.ctp in app/View/Books/.

How to do it...

Perform the following steps:

  1. Add the following beforeFilter() method to the BooksController class:
    public function beforeFilter() { parent::beforeFilter(); if ($this->request->is('ajax')) { $this->response->disableCache(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required