newYii newYii - 2 years ago 226
PHP Question

How to create pager in Yii2?

I was searching how to create pager in Yii2 using LinkPage widget.

Is there any example? I am new in Yii, so any help would be good.

Answer Source

It is simple

$dataProvider = new ActiveDataProvider([
    'query' => User::find(),
    'pagination' => array('pageSize' => 50),

echo \yii\widgets\LinkPager::widget([

Or if you don't use dataProvider you should use this:

$query = User::find();
$pagination = new Pagination(['totalCount' => $query->count(), 'pageSize'=>30]);

echo \yii\widgets\LinkPager::widget([
    'pagination' => $pagination,
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download