2

should be a simple fix but I'm not exactly sure why my LinkPager isn't showing here. My controller action is:

public function actionIndex()
{
    $query = Shout::find()->orderBy(['id' => SORT_DESC]);
    $countQuery = count($query);
    $pagination = new Pagination(
        [
            'totalCount' => $countQuery,
            'pageSize' => 5
        ]
    );
    $shouts = $query->offset($pagination->offset)
        ->limit($pagination->limit)
        ->all();

    return $this->render(
        'index',
        [
            'shouts' => $shouts,
            'pagination' => $pagination
        ]
    );

}

And my LinkPager widget is:

use yii\widgets\LinkPager;
echo LinkPager::widget(
    [
        'pagination' => $pagination
    ]
);

And while the pageSize is being limited to 5, I do not see the page selection below. Any help would be appreciated.

Muhammad Omer Aslam
  • 22,976
  • 9
  • 42
  • 68
D. Milk
  • 75
  • 8

1 Answers1

1

You need to provide the $query->count() rather than count($query); change your line in the controller action

from

$countQuery = count($query);

to

$countQuery = $query->count();
Muhammad Omer Aslam
  • 22,976
  • 9
  • 42
  • 68