1.Yii2分页插件
//分页插件
        $query = Country::find();
        $countQuery = clone $query;
        $pages = new Pagination(['totalCount' => $countQuery->count(),'pageSize' => '5']);
        $models = $query->offset($pages->offset)
            ->limit($pages->limit)
            ->all();
        return $this->render('index', [
            'models' => $models,
            'pages' => $pages,
        ]);
1.Yii2分页排序
//排序
        $sort = new Sort([
            'attributes' => [
                'population' => [
                    'desc' => ['population'=>SORT_DESC],
                    'asc' => ['population'=>SORT_ASC],
                    'default' => SORT_DESC,
                    'label' =>'#population',
                ],
            ],
            'defaultOrder' => ['attributes' => SORT_DESC], // 看这里看这里看这里,重要的话说三遍
        ]);
        $models = Country::find() ->orderBy($sort->orders)->all();
        return $this->render('index', [
            'models' => $models,
            'sort' => $sort,
        ]);

上一篇:Yii2学习笔记二十七:不用composer 手动安装插件

下一篇:wamp怎么配置虚拟主机