yii2 Active Record Find all records


Example

Post::find()->all();
// SELECT * FROM post

or the shorthand

(Returns an active record model instance by a primary key or an array of column values.)

Post::findAll(condition);

returns an array of ActiveRecord instances.

Find All with where Condition

$model = User::find()
        ->where(['id' => $id])
        ->andWhere('status = :status', [':status' => $status])
        ->all();

Find All with orderBy

$model = User::find()
         ->orderBy(['id'=>SORT_DESC])
        ->all();
Or

$model = User::find()
         ->orderBy(['id'=>SORT_ASC])
        ->all();