支付宝赞助帐号:service@kuitao8.com 

yii2.0分页的方法

Created2015-04-29   Views 2110    Author 懒人程序
function actionIndex()
{
    $query = Article::find()->where(['status' => 1]);
    $countQuery = clone $query;
    $pages = new Pagination(['totalCount' => $countQuery->count()]);
    $models = $query->offset($pages->offset)
        ->limit($pages->limit)
        ->all();

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

View:

foreach ($models as $model) {
    // display $model here
}

// display pagination
echo LinkPager::widget([
    'pagination' => $pages,
]);
上一篇: yii2原生态sql操作
下一篇: php往数组的随机位置,插入一个元素(其他元素,依次后移)
支持键盘 ← →

邮件订阅

订阅我们的精彩内容