ActiveRecord-find.md 845 Bytes
Newer Older
Qiang Xue committed
1
The returned [[ActiveQuery]] instance can be further customized by calling
2 3
methods defined in [[ActiveQuery]] before `one()`, `all()` or `value()` is
called to return the populated active records:
Qiang Xue committed
4 5 6 7

~~~
// find all customers
$customers = Customer::find()->all();
8

Qiang Xue committed
9 10 11 12 13
// find all active customers and order them by their age:
$customers = Customer::find()
    ->where(array('status' => 1))
    ->orderBy('age')
    ->all();
14

Qiang Xue committed
15 16
// find a single customer whose primary key value is 10
$customer = Customer::find(10);
17

Qiang Xue committed
18 19
// the above is equivalent to:
$customer = Customer::find()->where(array('id' => 10))->one();
20

Qiang Xue committed
21 22
// find a single customer whose age is 30 and whose status is 1
$customer = Customer::find(array('age' => 30, 'status' => 1));
23

Qiang Xue committed
24 25
// the above is equivalent to:
$customer = Customer::find()->where(array('age' => 30, 'status' => 1))->one();
26
~~~