谁一开始就是大神?

默认排序问题[2.0]

看了下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,非常感谢

赞(0) 打赏
未经允许不得转载:菜鸟之家 » 默认排序问题[2.0]

评论 抢沙发

登录

找回密码

注册