I want to create a line of code to create paging in my Web Service with Yii2 and I want the results like in Api The Movie there is param page=1. After I made the observation on Google, I found a way to make paging by adding limit and offsets in my Controller but the result fails, offset only add one id for example result from json 1 - 10 if i add offset in controller it show result 2 - 11
My Controller
public function actionGetdatapage($EmployeeId, $LeaveGroup, $Status, $Flag){
$param['EmployeeId'] = $EmployeeId;
$param['LeaveGroup'] = $LeaveGroup;
$param['Status'] = $Status;
$param['Flag'] = $Flag;
return $this->getListrequestpage($param);
}
public function getListrequestpage($param){
\Yii::$app->response->format = \yii\web\Response:: FORMAT_JSON;
$data = HrAttLeaveReq::find()
->joinwith('employee')
->joinwith('dept')
->joinwith('branch')
->joinwith('leavetype')
->joinwith('position')
->where([
'EmployeeId' => $param['EmployeeId'],
'LeaveGroup' => $param['LeaveGroup'],
'Status' => $param['Status'],
'HrAttLeaveReq.Flag' => $param['Flag']
])
->limit(10)
->offset(0)
->asArray()
->orderBy(['ReqNo' => SORT_ASC])
->all();
$array = array();
$i = -1;
foreach($data as $d){
$i++;
$array[$i]['Method'] = 'Request';
$array[$i]['ReqNo'] = $d['ReqNo'];
$array[$i]['Branch'] = $d['branch']['Name'];
$array[$i]['DeptId'] = $d['employee']['DeptId'];
$array[$i]['Departement_Position'] = $d['dept']['Departement'] . ', ' . $d['position']['Position'];
$array[$i]['Name'] = $d['employee']['Name'];
$array[$i]['Photo'] = $d['employee']['Photo'];
$array[$i]['Gender'] = $d['employee']['Gender'];
if($d['StartDate'] == $d['EndDate']){
$array[$i]['Date'] = date('l, d M Y', strtotime($d['StartDate']));
}else{
$array[$i]['Date'] = date('l, d M Y', strtotime($d['StartDate'])) . ' - ' . date('l, d M Y', strtotime($d['EndDate']));;
}
$array[$i]['LeaveGroup'] = $d['LeaveGroup'];
$array[$i]['LeaveType'] = $d['LeaveType'];
$array[$i]['Code_Status'] = $d['Status'];
$array[$i]['Type'] = $d['leavetype']['Type'];
$array[$i]['Description'] = '- ' . $d['Description'];
if ($d['Status'] == 0) {
$array[$i]['Status'] = "PENDING";
}
if ($d['Status'] == 1) {
$array[$i]['Status'] = "APPROVED";
}
if ($d['Status'] == 2) {
$array[$i]['Status'] = "DENIED";
}
$array[$i]['Flag'] = $d['Flag'];
}
$result = array();
$result['value'] = empty($array) ? 0 : 1;
$result['status'] = true;
$result['result'] = $array;
return $result;
}
The Result is
{
"value": 1,
"status": true,
"result": [
{
"Method": "Approval",
"ReqNo": "RO170363",
"Branch": "DCA CINERE",
"DeptId": "IT",
"Departement_Position": "Finance & Accounting, Developer",
"Name": "ALDAN RIZKI",
"Photo": "male.png",
"Gender": "m",
"Date": "Friday, 08 Sep 2017",
"LeaveGroup": "S",
"LeaveType": "S",
"Code_Status": "1",
"Type": "SAKIT",
"Description": "- This is Description ! ",
"Status": "APPROVED",
"Flag": "1"
}
]
}
I need the result like in Api The Movie
{
"page": 1,
"total_results": 7052,
"total_pages": 353,
"results": [
{
"vote_count": 580,
"id": 19404,
"video": false,
"vote_average": 9,
"title": "Dilwale Dulhania Le Jayenge",
"popularity": 43.694292,
"poster_path": "/2gvbZMtV1Zsl7FedJa5ysbpBx2G.jpg",
"original_language": "hi",
"original_title": "Dilwale Dulhania Le Jayenge",
"genre_ids": [
35,
18,
10749
],
"backdrop_path": "/nl79FQ8xWZkhL3rDr1v2RFFR6J0.jpg",
"adult": false,
"overview": "Raj is a rich, carefree, happy-go-lucky second generation NRI. Simran is the daughter of Chaudhary Baldev Singh, who in spite of being an NRI is very strict about adherence to Indian values. Simran has left for India to be married to her childhood fiancé. Raj leaves for India with a mission at his hands, to claim his lady love under the noses of her whole family. Thus begins a saga.",
"release_date": "1995-10-20"
},
]
}
So how to add param for page=1 ?