Answer the question
In order to leave comments, you need to log in
How to display posts using pagination in yii2?
How to display posts using pagination in yii2?
For example, the first page of the query displays 10 records.
The second page displays records from 11 records to 20 records per page.
How to implement it?
Answer the question
In order to leave comments, you need to log in
Maxim Fedorov said everything correctly, as an alternative:
www.yiiframework.com/doc-2.0/yii-data-pagination.html
Well, you can use ActiveDataProvider without GridView and ListView widgets. Since it can return the above proposed Pagination class, paired with LinkPager.
//экшен
$query = Post::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 20,
],
]);
//вьюха
foreach ($dataProvider->getModels() as $model) {
echo $model->id;
}
echo LinkPager::widget([
'pagination' => $dataProvider->pagination,
]);
Google the GridView
ListView
for instructions and explanations already ... it’s easy enough
, in general, they display data:
GridView displays rigidly in a table (you can set some settings and fields)
ListView can display according to an individual template and is also flexibly configured
In the ListView, you can also display paganization in your own way, the widget can be "disassembled" into parts, if you need paganization, the number of pages and the number of records to be in different places, never be afraid to experiment. Practice, try
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question