Yii Framework 2 : Custom Pagination

Yii Framework 2 : Custom Pagination

برای ایجاد صفحه بندی (pagination ) شخصی خود به صورت زیر می توانید عمل کنید:
ابتدا در controller

function actionIndex()
{
   $query = Comment::find()->where(['status' => Main::STATUS_PUBLISH]);
        $countQuery = clone $query;
        $pages = new Pagination([
            'totalCount' => $countQuery->count(), // مجموع کل رکورد ها
            'pageParam' => 'comment-page',// نام پیجر - زمانی که از چند پیجر در یک صفحه استفاده می شود جهت جدا سازی
            'pageSize'=>10 // تعداد آیتم در هر صفحه
        ]);
        $model = $query->offset($pages->offset)
            ->limit($pages->limit)
            ->all();
        return $this->render('comment-history', [
            'model' => $model,
            'pages' => $pages,
            'count' => $countQuery->count(),
        ]);
}

Yii Framework 2 : Custom Pagination

در ویو

foreach ($models as $model) {
    // display $model here
}
 <div class="pager default text-center">
 <?= LinkPager::widget([
'pagination' => $pages,
'activePageCssClass' => 'pager-item is-active',
//  'nextPageCssClass' => 'pager-next',
//  'prevPageCssClass' => 'pager-prev',
// 'nextPageLabel' => '',
//  'prevPageLabel' => '',

 'options' => [
 'class'=>'pager-items'
  ],
 ]); ?>
</div>

Yii Framework 2 : Custom Pagination

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *