N
N
nepster-web2014-04-11 03:04:40
Yii
nepster-web, 2014-04-11 03:04:40

Yii2 why pagination numbering is 1 page behind?

Implemented pagination like this:

public function actionArticles($page = 1)
  {
        $query = Blog::getArticles();
        $countQuery = clone $query;
        $pages = new Pagination(['totalCount' => $countQuery->count()]);
        $pages->page = $page;
        $models = $query->offset($pages->offset)
        ->limit($pages->limit)
        ->all();
        
        return $this->render('articles', [
            'articles' => $models,
            'pages' => $pages,
        ]);
    }

Everything works, except for one detail, for some reason yii2 counts pages from 0 and when I pass 1 page, it shows content from page 2.
Please tell me why this is happening and what to do about it (just add the line $page -= 1)?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
vyachin, 2015-04-07
@vyachin

https://github.com/yiisoft/yii2/blob/master/framew... here, as if directly written, the numbering starts from 0
and here is how everything works inside https://github.com/yiisoft/yii2/blob/master /framew...
or you can remove the parameter from actionArticles, Pagination will pick it up by itself. Parameter name can be customized https://github.com/yiisoft/yii2/blob/master/framew...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question