您好,我正在使用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;
}
答案 0 :(得分:0)
如果您想在网站中添加自定义pageingnation那么这是Controller的基本代码
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/