【问题标题】:Yii pagination reverse numbersYii 分页反向数字
【发布时间】:2014-02-11 11:03:18
【问题描述】:

我需要在 CPagination 中创建反向数字...

默认为:

上一页 1 2 3 4 下一页

我需要:

上一页 4 3 2 1 下一页

Widget为CListview,文章按最新排序。

CPagination 有可能吗?

【问题讨论】:

    标签: yii pagination reverse clistview


    【解决方案1】:

    是的,这是可能的。

    请检查此扩展程序。 http://www.yiiframework.com/extension/yii2-reversed-pagination/

    在控制器中:

    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,
                ]
            );
        }
    

    在视图中:

    foreach($models as $model): 
          // display a model...
        endforeach; 
    
    
        echo \loveorigami\pagination\ReverseLinkPager::widget([
            'pagination' => $pages,
            'registerLinkTags' => true
        ]);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-20
      • 1970-01-01
      • 2013-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-18
      • 1970-01-01
      相关资源
      最近更新 更多