jimgwhit
(Kpsklab)
October 10, 2017, 1:44am
1
In the docs and stackoverflow I can do this:
$pages = new Pagination(['totalCount' => $count, 'defaultPageSize' => 5]);
But how and where do you add in the other querystring parameters, like
yoursite.com/site?page=2&color=blue&size=large
If you returned a search result where does the &color=blue&size=large go.
I googled and searched yii site for appending querystring parameters to pagination.
Like laravel you just pass along using appends:
{{ $users->appends(['color' => $color])->links() }}
Thanks
[s]
Edit, I believe this is it, correct me if wrong:
$pages = new Pagination(['totalCount' => $count, 'defaultPageSize' => 5, 'params' => array('foo' => 'bar')]);
I just added params array after count.
Maybe this will help someone, docs should cover it though.[/s]
Well spoke too soon, I am just getting the same page of data over and over.
jimgwhit
(Kpsklab)
October 10, 2017, 3:29am
2
Ok I ran my test database through this:
public function actionDlist()
{
$sch = Yii::$app->request->get('sch', 'c');
$schquy = $sch . "%";
$page = Yii::$app->request->get('page', '1');
$count = Dog::find()->where(['like', 'dogname', $schquy, false])->count();
echo $count; //33 and I confirmed this
$query = Dog::find()->where(['like', 'dogname', $schquy, false]);
$pages = new Pagination(['totalCount' => $count, 'defaultPageSize' => 5, 'params' => array('sch' => $sch)]);
$pages->setPage($page);
$dogs = $query->offset($pages->offset)
->limit($pages->limit)
->all();
$this->layout = 'dog/artp';
return $this->render('dlist', [
'dogs' => $dogs,
'pages' => $pages
]);
}
And with that the paginator is somewhat working. It actually correctly paginates through page 1 through 6. There are 33 results, but when you click page 7, nothing. So the paginator isn’t picking up the last page.
Any tips here.