sphinx\ActiveRecord find()

find() public static method

Creates an \yii\sphinx\ActiveQueryInterface instance for query purpose.

The returned \yii\sphinx\ActiveQueryInterface instance can be further customized by calling methods defined in \yii\sphinx\ActiveQueryInterface before one() or all() is called to return populated ActiveRecord instances. For example,

// find the customer whose ID is 1
$customer = Customer::find()->where(['id' => 1])->one();

// find all active customers and order them by their age:
$customers = Customer::find()
    ->where(['status' => 1])
    ->orderBy('age')
    ->all();

This method is also called by yii\db\BaseActiveRecord::hasOne() and yii\db\BaseActiveRecord::hasMany() to create a relational query.

You may override this method to return a customized query. For example,

class Customer extends ActiveRecord
{
    public static function find()
    {
        // use CustomerQuery instead of the default ActiveQuery
        return new CustomerQuery(get_called_class());
    }
}

The following code shows how to apply a default condition for all queries:

class Customer extends ActiveRecord
{
    public static function find()
    {
        return parent::find()->where(['deleted' => false]);
    }
}

// Use andWhere()/orWhere() to apply the default condition
// SELECT FROM customer WHERE `deleted`=:deleted AND age>30
$customers = Customer::find()->andWhere('age>30')->all();

// Use where() to ignore the default condition
// SELECT FROM customer WHERE age>30
$customers = Customer::find()->where('age>30')->all();


public static yii\sphinx\ActiveQuery find ( )
return yii\sphinx\ActiveQuery

The newly created yii\sphinx\ActiveQuery instance.

doc_Yii
2016-10-30 17:11:36
Comments
Leave a Comment

Please login to continue.