maandag 29 oktober 2007

Use helpers in your application

It is advised to make use of helpers in your application. Your code becomes clean and more flexible because the helpers are short and clear, and they handle the paths to the file referenced. For example, to quickly show an image in your view, use:


< ?= $html->image('9.jpg') ?>

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().

maandag 1 oktober 2007

Basic Task list with Ajax

Graham Bird has written a very nice tutorial on creating a Basic Task list with Ajax. Have a look at it here (http://grahambird.co.uk/cake/tutorials/ajax.php).