Reputation: 75
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.
Upvotes: 2
Views: 1399
Reputation: 23768
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();
Upvotes: 1