如果我在数组中固定了10个数据,请将pagesize设置为10,并将totalcount设置为50(5页)。 问题是,我在第2页上时只能显示10个数据,所以无法显示我的数据(空白),因此我必须加载20个数据才能在第2页上显示行。
这是我的代码: 控制器
public function actionIndex()
{
$searchModel = new SampleSearch();
$data = \Sample\Api::get('https://example.com/get-data?page=2');
/**
* $data
* {
* "totalCount": 50,
* "data": [
* {
* "_id": 11,
* "name": "Baron"
* },
* {
* "_id": 12,
* "name": "John Doe"
* },
* {
* "_id": 13,
* "name": "Michael Scofield"
* },
* {
* "_id": 14,
* "name": "Wentworth Miller"
* },
* {
* "_id": 15,
* "name": "Valentino Rossi"
* },
* {
* "_id": 16,
* "name": "Marc Marquez"
* },
* {
* "_id": 17,
* "name": "David De Gea"
* },
* {
* "_id": 18,
* "name": "Roronoa Zoro"
* },
* {
* "_id": 19,
* "name": "Mohamed Salah"
* },
* {
* "_id": 20,
* "name": "Shadow"
* }
* ]
* }
*/
$dataProvider = new ArrayDataProvider([
'allModels' => $data->data,
'pagination' => [
'pageSize' => 10,
'page' => isset($_GET['page']) ? ((int)$_GET['page'] - 1) : 0,
],
'sort' => [
'attributes' => ['_id'],
],
'totalCount' => $data->totalCount,
]);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
如何仅用10个数据加载第2页?
先谢谢 对不起,我的英语