本文整理匯總了PHP中yii\db\ActiveQuery::addOrderBy方法的典型用法代碼示例。如果您正苦於以下問題:PHP ActiveQuery::addOrderBy方法的具體用法?PHP ActiveQuery::addOrderBy怎麽用?PHP ActiveQuery::addOrderBy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類yii\db\ActiveQuery
的用法示例。
在下文中一共展示了ActiveQuery::addOrderBy方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: buildQuery
/**
* @param array $attributes
* @return \yii\db\ActiveQuery
*/
public function buildQuery($attributes = [])
{
$this->setAttributes($attributes);
if (!empty($this->modelClass) && empty($this->query)) {
/** @var ActiveRecord $model */
$model = new $this->modelClass();
$this->query = $model->find();
}
if ($this->validate()) {
if (!empty($this->query)) {
$this->filterAttributes();
}
if (($sort = $this->getSort()) !== false) {
$this->query->addOrderBy($sort->getOrders());
}
if ($this->whereEnabled && $this->where) {
$this->query = $this->setWhere($this->query, $this->where);
}
return $this->query;
}
return null;
}
示例2: prepareQuery
/**
*
* Apply current condition will be applied to a query using this function.
*
* @param \yii\db\ActiveQuery $query The query object which current condition must be applied to
*/
public function prepareQuery($query)
{
$field = $this->functionObj->prepareSql();
if (!$field) {
return NULL;
}
switch ($this->operation) {
case 'select':
// Here I need to add property to the target class accroding to alias
$query->addSelect([$this->alias => $field]);
break;
case 'where':
$query->andWhere($field);
break;
case 'group':
$query->addGroupBy($field);
break;
case 'order':
$query->addOrderBy($field);
break;
case 'order_inv':
$query->addOrderBy([$field => SORT_DESC]);
break;
}
}
示例3: sort
public function sort(ActiveQuery $query)
{
$query->addOrderBy('sort DESC');
return $query;
}