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

Custom finders

Instead of creating custom getter methods in your models, like we did in our previous recipe by running find() internally and returning an array of results, you can also use the built-in feature to define custom finder methods. These can modify the find options before the query is executed or even fix the returned results before they are used.

Custom finders provide a better interface to reuse common find operation parameters. Instead of working only with the result arrays (containing the database rows in array format), we'll be able to work with the find options first.

In this recipe, we'll create a custom finder to retrieve the latest products in our database, injecting a stored in several warehouses field on the fly, once the results ...

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