ActiveRecord-find.md 825 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
// find all active customers and order them by their age:
$customers = Customer::find()
Alexander Makarov committed
11
    ->where(['status' => 1])
Qiang Xue committed
12 13
    ->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
// the above is equivalent to:
Alexander Makarov committed
19
$customer = Customer::find()->where(['id' => 10])->one();
20

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

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