Yii pagination reverse numbers

233 Views Asked by At

I need to create reverse numbers in CPagination...

Default is:

Prev 1 2 3 4 Next

I need:

Prev 4 3 2 1 Next

Widget is CListview and articles is sorted by newest.

It's possible in CPagination?

1

There are 1 best solutions below

0
On

Yes it is possible.

Please check this extension. http://www.yiiframework.com/extension/yii2-reversed-pagination/

In controller:

public function actionIndex()
    {
        $query = Article::find()->all();
        $countQuery = clone $query;
        $pages = new \loveorigami\pagination\ReversePagination(
            [
                'totalCount' => $countQuery->count(),
                'pageSize' => 10, // or in config Yii::$app->params['pageSize']
            ]
        );
        $pages->pageSizeParam = false;
        $models = $query->offset($pages->offset)
            ->limit($pages->limit)
            ->all();

        return $this->render('index',
            [
                'models'  => $models,
                'pages' => $pages,
            ]
        );
    }

In View:

foreach($models as $model): 
      // display a model...
    endforeach; 


    echo \loveorigami\pagination\ReverseLinkPager::widget([
        'pagination' => $pages,
        'registerLinkTags' => true
    ]);