Reputation: 101
Hi i tried to used pagination without dataProvider. Can I used this like:
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
]);
}
And in my view:
<?php echo \yii\widgets\LinkPager::widget([
'pagination' => $pagination,
]); ?>
My $count return me :
int 12
and in my view i can see pagination with 1,2 but it not work becosue it show me all 12 records but I want to see this 10 records. I have 2 buttons of page but it still show me all records. What can I do to fix that?
my view:
<?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,
]); ?>
Upvotes: 0
Views: 805
Reputation: 1417
Its becoz Your $messages variable contains all values , its not being limited according to your pagination
Try This
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
]);
}
Upvotes: 1