Examples:
Posts::find('all'); // returns all records
Posts::find('count'); // returns a count of all records
The first ten records that have 'author' set to 'Bob'.
Posts::find('all', array(
'conditions' => array('author' => 'Bob'),
'limit' => 10
));
First record where the id matches 23.
Posts::find('first', array(
'conditions' => array('id' => 23)
));
Shorthands:
Shorthand for find first by primary key.
Posts::find(23);
Also works with objects.
Posts::find(new MongoId(23));
public static find ( string | object | integer $type, array $options = [] ) : mixed | ||
$type | string | object | integer | The name of the finder to use. By default the
following finders are available. Custom finders can be added via `Model::finder()`.
- `'all'`: Returns all records matching the conditions.
- `'first'`: Returns the first record matching the conditions.
- `'count'`: Returns an integer count of all records matching the conditions.
- `'list'`: Returns a one dimensional array, where the key is the (primary)
key and the value the title of the record (the record must have a `'title'`
field). A result may look like: `array(1 => 'Foo', 2 => 'Bar')`.
Instead of the name of a finder, also supports shorthand usage with an object or
integer as the first parameter. When passed such a value it is equal to
`Model::find('first', array('conditions' => array(' |
$options | array | Options for the query. By default, accepts: - `'conditions'` _array_: The conditions for the query i.e. `'array('is_published' => true)`. - `'fields'` _array|null_: The fields that should be retrieved. When set to `null` and by default, uses all fields. To optimize query performance, limit the fields to just the ones actually needed. - `'order'` _array|string_: The order in which the data will be returned, i.e. `'created ASC'` sorts by created date in ascending order. To sort by multiple fields use the array syntax `array('title' => 'ASC', 'id' => 'ASC)`. - `'limit'` _integer_: The maximum number of records to return. - `'page'` _integer_: Allows to paginate data sets. Specifies the page of the set together with the limit option specifying the number of records per page. The first page starts at `1`. |
return | mixed | The result/s of the find. Actual result depends on the finder being used. Most often this is an instance of `lithium\data\Collection` or `lithium\data\Entity`. |