如何在 Yii 中使用下一个和上一个按钮


how to use next and previous button in yii

你好,我有用于显示页码的 Yii 代码,我只想使用

"

下一个"和"上一个"按钮 我怎样才能实现这一点

这是我的代码

public function getNextId()
{
    $record=self::model()->find(array(
            'condition' => 'id>:current_id',
            'order' => 'id ASC',
            'limit' => 1,
            'params'=>array(':current_id'=>$this->id),
    ));
    if($record!==null)
        return $record->id;
    return null;
}
public function getPreviousId()
{
    $record=self::model()->find(array(
            'condition' => 'id<:current_id',
            'order' => 'id DESC',
            'limit' => 1,
            'params'=>array(':current_id'=>$this->id),
    ));
    if($record!==null)
        return $record->id;
    return null;
}

如果你想在网站中添加自定义页面,那么这是控制器的基本代码

function actionIndex(){
$query = User::find()->where(['status' => 1]);
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count()]);
$models = $query->offset($pages->offset)
    ->limit($pages->limit)
    ->all();
return $this->render('index', [
     'models' => $models,
     'pages' => $pages,
]);}

如需查看,请添加此代码

foreach ($models as $model) { // Do model Code
} echo LinkPager::widget([    'pagination' => $pages,]);

阅读更多,请获取此链接:http://www.bsourcecode.com/yiiframework2/custom-pagination-in-yiiframework-2-0/