Yii Framework Forum: RESTful API Pagination - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

RESTful API Pagination

#1 User is offline   faizanktk 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 22-September 17

Posted 22 September 2017 - 10:17 AM

I made an API in Yii2.

Here is my code

$provider = new ActiveDataProvider([
'query' => $model->getReservations($start_time, $end_time),
'pagination' => [
'defaultPageSize' => 2 ,
'pageSize' => 2,
'pageSizeLimit' => [0, 2],
],

]);
$links = $provider->pagination->getLinks();
$count = $provider->getPagination();
return (new ApiResponse)->success(["count" => $count, "links" => $links], ApiResponse::SUCCESSFULL, null);

And the result is:
{
"name": "Success",
"message": "Success",
"code": 200,
"status": "",
"type": "Response",
"models": {
"count": {
"pageParam": "page",
"pageSizeParam": "per-page",
"forcePageParam": true,
"route": null,
"params": null,
"urlManager": null,
"validatePage": true,
"totalCount": 12,
"defaultPageSize": 2,
"pageSizeLimit": [
0,
2
]
},
"links": {
"self": "/backoffice/api/web/index.php/v1/reservations/member/8?page=1"
}
}
}

The problem i am facing is only 'self' link is present. Where are the other linkss i-e last, next, previous and first
0

#2 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,165
  • Joined: 17-January 09
  • Location:Russia

Posted 22 September 2017 - 02:15 PM

Please provide code for

return (new ApiResponse)->success(

Yii 2.0 Development Cookbook

Enjoying Yii? Star us at github

Support me so I work on Yii fulltime: https://www.patreon.com/samdark
0

#3 User is offline   salem 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 25-August 12
  • Location:Tunisia

Posted 22 September 2017 - 03:32 PM

Also something is wrong with URL, isn't that resource n°8 instead of a paginated collection?

"links": {
   "self": "/backoffice/api/web/index.php/v1/reservations/member/8?page=1"
}

0

#4 User is offline   faizanktk 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 22-September 17

Posted 24 September 2017 - 04:38 AM

View Postsamdark, on 22 September 2017 - 02:15 PM, said:

Please provide code for

return (new ApiResponse)->success(




I didn't understand it. can you give answer properly
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users