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

Basic search and filter

Displaying paginated records can be great to allow your users to easily navigate through large sets of data. However, it is even better when you can give them the option to search directly.

In this recipe, we're going to add a new search box for our packages. We'll use a LIKE condition in SQL to filter the resulting packages. This will do the trick for small datasets as a starting point.

Getting ready

For our recipe, we'll assume that you still have the packages table, Package model, and PackagesController, with the paginated index() action with the index.ctp view created from our previous recipe.

How to do it...

Perform the following steps:

  1. First, add the following search box to index.ctp in app/View/Packages/ right below the ...

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