Book Image

CakePHP 2 Application Cookbook - Third Edition

By : Watts
Book Image

CakePHP 2 Application Cookbook - Third Edition

By: Watts

Overview of this book

If you are a CakePHP developer looking to ease the burden of development, then this book is for you. As a headfirst dive into the framework, this collection of recipes will help you get the most out of CakePHP, and get your applications baked in no time. Even if you're not familiar with the framework, we'll take you from basic CRUD building to useful solutions that will aid in getting the job done quickly and efficiently.
Table of Contents (14 chapters)
13
Index

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();
      }
    }
  2. In the same class, add the following inventory_index() method (we will utilize the inventory prefix added in the previous chapter):
    public function inventory_index(...