3.7.3.1 find
find($type, $params)
$type is either 'all', 'first', 'count', 'list', 'neighbors' or 'threaded'. 'first' is the default find type.
$params is an array with any of the following available options as keys:
array(
'conditions' => array('Model.field' => $thisValue), //array of conditions
'recursive' => 1, //int
'fields' => array('Model.field1', 'Model.field2'), //array of field names
'order' => 'Model.created', //string or array defining order
'group' => array('Model.field'), //fields to GROUP BY
'limit' => n, //int
'page' => n //int
) array('conditions' => array('Model.field' => $thisValue), //array of conditions'recursive' => 1, //int'fields' => array('Model.field1', 'Model.field2'), //array of field names'order' => 'Model.created', //string or array defining order'group' => array('Model.field'), //fields to GROUP BY'limit' => n, //int'page' => n //int)
If you are using find('list'), the 'fields' key in $params defines the key, value and group
// generated list will be indexed by Post.id, with value of Post.title
$this->Post->find('list', array('fields'=>'Post.title'));
// generated list will be indexed by Post.slug, with value of Post.title
$this->Post->find('list', array('fields'=>array('Post.slug', 'Post.title')));
// generated list will be grouped by Post.author_id, and each group indexed (aka, optgroup) by Post.id, with value of Post.title
$this->Post->find('list', array('fields'=>array('Post.id', 'Post.title', 'Post.author_id')));
// generated list will be indexed by Post.id, with value of Post.title$this->Post->find('list', array('fields'=>'Post.title'));// generated list will be indexed by Post.slug, with value of Post.title$this->Post->find('list', array('fields'=>array('Post.slug', 'Post.title')));// generated list will be grouped by Post.author_id, and each group indexed (aka, optgroup) by Post.id, with value of Post.title$this->Post->find('list', array('fields'=>array('Post.id', 'Post.title', 'Post.author_id')));
If you wish to use an optgroup label from a parent table, be sure to set 'recursive'=>1 in the parameters.
If you are using find('neighbors'), a 'field' key in $params defines the field to analyze, and a 'value' key in the $params array defines the value to look at to determine the next and previous. Note that the 'field' and 'value' keys are not used for find('all') and this is a special case for find('neighbors').
// assuming we have id's from 1-10, we'll see prev set to 1 and next set to 3
$this->Post->id = 2;
$one = $this->Post->find('neighbors');
// To get the neighboring data using a different field..
$two = $this->Post->find('neighbors', array('field'=>'Post.title', 'value'=>$data['Post']['title']));
// assuming we have id's from 1-10, we'll see prev set to 1 and next set to 3$this->Post->id = 2;$one = $this->Post->find('neighbors');// To get the neighboring data using a different field..$two = $this->Post->find('neighbors', array('field'=>'Post.title', 'value'=>$data['Post']['title']));
For backwards compatibility, find also accepts the previous syntax:
find(string $conditions, array $fields, string $order, int $recursive)
