I am using a REST API in Yii2 with Authorization Bearer
I have configured the actionUpdate completely but somehow when using PUT to update the data, I am getting null value when I try to get the post data,
print_r($request->getBodyParam('member_id'))
Get below result when print_r(Yii::$app->request->bodyParams):
Content -type is multipart/form-data
Array ( [------WebKitFormBoundaryAF3YWAApi5BxYUb2 Content-Disposition:_form-data;_name] => "member_id" 274505 ------WebKitFormBoundaryAF3YWAApi5BxYUb2 Content-Disposition: form-data; name="claim_type" 3 ------WebKitFormBoundaryAF3YWAApi5BxYUb2 Content-Disposition: form-data; name="visit_date" 2016-10-12 ------WebKitFormBoundaryAF3YWAApi5BxYUb2 Content-Disposition: form-data; name="provider_id" 0 ------WebKitFormBoundaryAF3YWAApi5BxYUb2 Content-Disposition: form-data; name="diagnosis" fevercc ------WebKitFormBoundaryAF3YWAApi5BxYUb2 Content-Disposition: form-data; name="reimbursement" 1 ------WebKitFormBoundaryAF3YWAApi5BxYUb2 Content-Disposition: form-data; name="non_panel" true ------WebKitFormBoundaryAF3YWAApi5BxYUb2 Content-Disposition: form-data; name="provider_name" klinik abc ------WebKitFormBoundaryAF3YWAApi5BxYUb2 Content-Disposition: form-data; name="reimbursement_reason" near to house ------WebKitFormBoundaryAF3YWAApi5BxYUb2 Content-Disposition: form-data; name="invoice_no" 1245 ------WebKitFormBoundaryAF3YWAApi5BxYUb2 Content-Disposition: form-data; name="medical_leave" 0 ------WebKitFormBoundaryAF3YWAApi5BxYUb2 Content-Disposition: form-data; name="leave_form" ------WebKitFormBoundaryAF3YWAApi5BxYUb2 Content-Disposition: form-data; name="amount_incurred" 24 ------WebKitFormBoundaryAF3YWAApi5BxYUb2-- )
Below is my actionUpdate
public function actionUpdate($id) {
$claim = $this->findModel($id);
$claim->scenario = 'update';
if ( $claim->status_id == 1 ) {
$request = Yii::$app->request;
if (isset($request)) {
$member_id = $request->getBodyParam('member_id');
$claim_type = $request->getBodyParam('claim_type');
$visit_date = $request->getBodyParam('visit_date');
$provider_id = $request->getBodyParam('provider_id');
$diagnosis = $request->getBodyParam('diagnosis');
$reimbursement = $request->getBodyParam('reimbursement');
$userlogin_id = Yii::$app->user->identity->id;
if ($claim->validate() ) {
$claim->save();
return array('id'=>$claim->id,'msg'=>'Successfully update claim');
} else {
return (ActiveForm::validate($claim));
}
}
} else {
throw new \yii\web\MethodNotAllowedHttpException('You are not allowed to update data');
}
}