看了下SQL默认没有排序,怎么做到默认id desc?
public function actionIndex()
{
$sort = new Sort([
'attributes' => [
'id' => [
'desc' => ['id'=>SORT_DESC],
'asc' => ['id'=>SORT_ASC],
'default' => SORT_DESC,
'label' =>'#Id',
],
'hot' => [
'asc' => ['hot'=>SORT_ASC],
'desc' => ['hot'=>SORT_DESC],
'label' =>'#即时热度',
],
'add_hot' => [
'asc' => ['add_hot'=>SORT_ASC],
'desc' => ['add_hot'=>SORT_DESC],
'label' =>'#增减热度',
],
],
]);
$query = Dynamic::find();
$pages = new Pagination([
'defaultPageSize' => 10,
'totalCount' => $query->count(),
]);
$models = $query
->where(['status' => 0])
->orderBy($sort->orders)
->offset($pages->offset)
->limit($pages->limit)
->all();
return $this->render('index',[
'models' => $models,
'sort' => $sort,
'pages' => $pages,
]);
}
$query = Dynamic::find()->orderBy(['id' => SORT_DESC]);
请问,我设置一个默认排序后,想在前台页面自己点击某个head是自动排序(升或降)?如何写?模仿你的默认会写了,谢谢!
mark,非常感谢