db\BaseActiveRecord findAll()

findAll() public static method

Returns a list of active record models that match the specified primary key value(s) or a set of column values.

The method accepts:

  • a scalar value (integer or string): query by a single primary key value and return an array containing the corresponding record (or an empty array if not found).
  • a non-associative array: query by a list of primary key values and return the corresponding records (or an empty array if none was found). Note that an empty condition will result in an empty result as it will be interpreted as a search for primary keys and not an empty WHERE condition.
  • an associative array of name-value pairs: query by a set of attribute values and return an array of records matching all of them (or an empty array if none was found). Note that ['id' => 1, 2] is treated as a non-associative array.

This method will automatically call the all() method and return an array of ActiveRecord instances. For example,

// find the customers whose primary key value is 10
$customers = Customer::findAll(10);

// the above code is equivalent to:
$customers = Customer::find()->where(['id' => 10])->all();

// find the customers whose primary key value is 10, 11 or 12.
$customers = Customer::findAll([10, 11, 12]);

// the above code is equivalent to:
$customers = Customer::find()->where(['id' => [10, 11, 12]])->all();

// find customers whose age is 30 and whose status is 1
$customers = Customer::findAll(['age' => 30, 'status' => 1]);

// the above code is equivalent to:
$customers = Customer::find()->where(['age' => 30, 'status' => 1])->all();
public static static[] findAll ( $condition )
$condition mixed

Primary key value or a set of column values

return static[]

An array of ActiveRecord instances, or an empty array if nothing matches.

doc_Yii
2016-10-30 16:56:43
Comments
Leave a Comment

Please login to continue.