dinsdag 2 oktober 2007

findAllBy is cool!

Suppose you have a field name in your database called type. CakePHP will automagically add a new function called findAllByType. For example, you can try: findAllByType('customer'); to find all fields with type=customer.

From the CakePHP manual:




* findAllBy
* string $value

These magic functions can be used as a shortcut to search your tables for a row given a certain field, and a certain value. Just tack on the name of the field you wish to search, and CamelCase it. Examples (as used in a Controller) might be:
$this->Post->findByTitle('My First Blog Post');
$this->Author->findByLastName('Rogers');
$this->Property->findAllByState('AZ');
$this->Specimen->findAllByKingdom('Animalia');

The returned result is an array formatted just as would be from find() or findAll().

Geen opmerkingen:

Een reactie posten