没有数据提供者的分页
问题描述:
嗨,我试图用没有dataProvider的分页。我可以用这个类似:没有数据提供者的分页
public function actionShowtest($id){
$model = $this->findModel($id);
$messages= \common\models\PrMessage::find()->where(['Rel_Dialog'=>$id])->all();
$count = count($messages);
$pagination = new Pagination(['totalCount' => $count, 'pageSize'=>10]);
return $this->render('messages', [
'model' => $model,
'messages'=>$messages,
'pagination'=>$pagination
]);
}
在我看来:
<?php echo \yii\widgets\LinkPager::widget([
'pagination' => $pagination,
]); ?>
我的$计数返回我:
INT 12
在我看来,我可以看到1,2分页,但它不起作用,因为它显示我所有12条记录,但我想看到这10条记录。我有2个页面按钮,但它仍然显示我所有的记录。我能做些什么来解决这个问题?
我的观点:
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
use yii\helpers\Url;
use yii\widgets\ListView;
/* @var $this yii\web\View */
/* @var $model common\models\BlogPost */
$this->title = $model->Id;
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Konwersacje'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="blog-post-view">
<?php foreach($model->prMessages as $msg): ?>
<?=$msg->relSender->Name.' '.$msg->relSender->Surname; ?>
<?=$msg->CreatedAt; ?>
<?=$msg->Text; ?>
<?php endforeach; ?>
</div>
<?php echo \yii\widgets\LinkPager::widget([
'pagination' => $pagination,
]); ?>
答
其becoz你的$消息变量包含的所有值,其根据您的分页并不限于
尝试这个
public function actionShowtest($id){
$model = $this->findModel($id);
$messagesQuery = \common\models\PrMessage::find()->where(['Rel_Dialog'=>$id]);
$pagination = new Pagination(['totalCount' => $messagesQuery->count(), 'pageSize'=>10]);
$messages = $messagesQuery->offset($messagesQuery->offset)
->limit($pagination->limit)
->all();
return $this->render('messages', [
'model' => $model,
'messages'=>$messages,
'pagination'=>$pagination
]);
}
仍有相同 – qwerty
所以即使在我们给出限制($ pagination-> limit)之后,你的第一页也会呈现12个项目? –
你能分享你的完整视图代码吗? –