我正在使用 REST API,Yii2 with Authorization Bearer
我已经完全配置了 actionUpdate,但不知何故,当我使用 PUT 更新数据时,当我尝试获取发布数据时,我得到空值,
print_r($request->getBodyParam('member_id'))
得到以下结果时print_r(Yii::$app->request->bodyParams):
Content -type is multipart/form-data
true ------WebKitFormBoundaryAF3YWAApi5BxYUb2 内容处置:表单数据;name="provider_name" klinik abc ------WebKitFormBoundaryAF3YWAApi5BxYUb2 Content-Disposition: form-data; name="reimbursement_reason" 离家近 ------WebKitFormBoundaryAF3YWAApi5BxYUb2 Content-Disposition: form-data; name="invoice_no" 1245 ------WebKitFormBoundaryAF3YWAApi5BxYUb2 内容处置:表单数据;name="medical_leave" 0 ------WebKitFormBoundaryAF3YWAApi5BxYUb2 内容处置:表单数据;name="leave_form" ------WebKitFormBoundaryAF3YWAApi5BxYUb2 Content-Disposition: form-data; name="amount_incurred" 24 ------WebKitFormBoundaryAF3YWAApi5BxYUb2--) klinik abc ------WebKitFormBoundaryAF3YWAApi5BxYUb2 Content-Disposition: form-data; name="reimbursement_reason" 离家近 ------WebKitFormBoundaryAF3YWAApi5BxYUb2 Content-Disposition: form-data; name="invoice_no" 1245 ------WebKitFormBoundaryAF3YWAApi5BxYUb2 内容处置:表单数据;name="medical_leave" 0 ------WebKitFormBoundaryAF3YWAApi5BxYUb2 内容处置:表单数据;name="leave_form" ------WebKitFormBoundaryAF3YWAApi5BxYUb2 Content-Disposition: form-data; name="amount_incurred" 24 ------WebKitFormBoundaryAF3YWAApi5BxYUb2--) klinik abc ------WebKitFormBoundaryAF3YWAApi5BxYUb2 Content-Disposition: form-data; name="reimbursement_reason" 离家近 ------WebKitFormBoundaryAF3YWAApi5BxYUb2 Content-Disposition: form-data; name="invoice_no" 1245 ------WebKitFormBoundaryAF3YWAApi5BxYUb2 内容处置:表单数据;name="medical_leave" 0 ------WebKitFormBoundaryAF3YWAApi5BxYUb2 内容处置:表单数据;name="leave_form" ------WebKitFormBoundaryAF3YWAApi5BxYUb2 Content-Disposition: form-data; name="amount_incurred" 24 ------WebKitFormBoundaryAF3YWAApi5BxYUb2--) 1245 ------WebKitFormBoundaryAF3YWAApi5BxYUb2 内容处置:表单数据;name="medical_leave" 0 ------WebKitFormBoundaryAF3YWAApi5BxYUb2 内容处置:表单数据;name="leave_form" ------WebKitFormBoundaryAF3YWAApi5BxYUb2 Content-Disposition: form-data; name="amount_incurred" 24 ------WebKitFormBoundaryAF3YWAApi5BxYUb2--) 1245 ------WebKitFormBoundaryAF3YWAApi5BxYUb2 内容处置:表单数据;name="medical_leave" 0 ------WebKitFormBoundaryAF3YWAApi5BxYUb2 内容处置:表单数据;name="leave_form" ------WebKitFormBoundaryAF3YWAApi5BxYUb2 Content-Disposition: form-data; name="amount_incurred" 24 ------WebKitFormBoundaryAF3YWAApi5BxYUb2--)
以下是我的行动更新
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');
}
}