Yii Framework 2 : Advanced Select Query

Scopes

Sample 1:

	
class User extends \yii\db\ActiveRecord
{
    namespace app\models;
    public static function olderThan($query, $age = 5)
    {
        $query->andWhere('userid > :age', [':age' => $age]);
    }
}
// call the scope function	
$model = User::find()->olderThan(5)->all();	 
Sample 2:
	
class User extends \yii\db\ActiveRecord
{
    // ...
    public static function active($query)
    {
        $query->andWhere('status = 1');
    }
}
// call the scope function
$model = User::find()
        ->active()
        ->all();