Archive for the ‘Models’ Category


Sep 20, 2007

Provide access to a model from a Component
Say you have a model called FoosFum in a file called foos_fum.php

$this->FoosFum = &new FoosFum();

Limit the size of your controller

If you only use a model in certain circumstances do not use the $uses array, use loadModel where you need it.


Google Group




Find Function

Aug 14, 2007

The find() function has the following parameters:

  • string $conditions
  • array $fields
  • string $order
  • int $recursive

Returns the specified (or all if not specified) fields from the first record that matches $conditions or FALSE if no data is found. Recursive must be -1 to not return any associated data.


$one_row = $this->ModelName->find('id = ' . clean_id,  null, null, -1);

Return example (i.e. value in $one_row):

    [ModelName] => Array
            [id] => 1000
            [name] => Ford
            [status] => A
            [created] => 2007-08-04 00:42:17
            [modified] => 2007-08-04 00:42:17


So to get the value of name to your view you could write:

$this->set('name', $one_row['ModelName']['name']);