本文整理汇总了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;
}