findAll() in yii
In the Yii framework, the findAll() method is used to retrieve all records from a database table that match a specified condition.
Note: This guide covers Yii 2 and Yii 3. In Yii 1.x, findAll() was a method of CActiveRecord, but it was deprecated in Yii 2.0.13 and removed in Yii 2.1. Modern Yii uses the query builder pattern. The yii\db\ActiveRecord class provides the find() method, which returns an ActiveQuery instance. Chaining where() and all() retrieves an array of active record objects, each representing a single database record.
For example, to retrieve all records from a table named "users" where the "status" column is equal to 1, you could use the following code:
Example of retrieving all records from a table in Yii
$users = User::find()->where(['status' => 1])->all();The query builder also allows you to specify sorting, pagination, and other options by chaining methods.
Example of retrieving all records with sorting in Yii
$users = User::find()
->where(['status' => 1])
->orderBy(['create_time' => SORT_DESC])
->all();You can also use with() to eager load related models and joinWith() to join related tables.