The method accepts:
- a scalar value (integer or string): query by a single primary key value and return the
corresponding record (or null if not found).
- a non-associative array: query by a list of primary key values and return the
first record (or null if not found).
- an associative array of name-value pairs: query by a set of attribute values and return a single record
matching all of them (or null if not found). Note that ['id' => 1, 2] is treated as a non-associative array.
That this method will automatically call the one() method and return an [[ActiveRecordInterface|ActiveRecord]]
instance. For example,
php
find a single customer whose primary key value is 10
$customer = Customer::findOne(10);
the above code is equivalent to:
$customer = Customer::find()->where(['id' => 10])->one();
find the first customer whose age is 30 and whose status is 1
$customer = Customer::findOne(['age' => 30, 'status' => 1]);
the above code is equivalent to:
$customer = Customer::find()->where(['age' => 30, 'status' => 1])->one();