How can I get param from Post react native? Post react native I try here to send some data to the request yii:
let body = {
demande_title:demande_title,
created_Date:created_Date,
updated_Date:updated_Date,
demande_Type:demande_Type,
demande_Action:demande_Action,
demande_status:demande_status,
demande_content:demande_content,
demande_color:demande_color,
utf_utilisateur_front_id:1
};
let response = await fetch(url, {
method: "POST",
headers: {
Authorization: `Bearer ${getState().auth.token}`,
"Content-Type": "application/json",
},
body: JSON.stringify(body),
});
if (!response.ok) {
throw new Error("Something went wrong !");
}
I want to get data with yii load param and insert(create new demand) in data base . Code Yii :
public function actionDemandeCreate()
{
$demande = new Demande();
$demande->load(Yii::$app->getRequest()->getBodyParams(), '');
if ($demande->save()) {
Yii::$app->response->statusCode = 201;
return [
'demande_id'=>$demande->id,
'demande_title'=>$demande->demande_title,
'created_Date'=>$demande->created_Date,
'updated_Date'=>$demande->updated_Date,
'demande_Type'=>$demande->demande_Type,
'demande_color'=>$demande->demande_color,
'demande_Action'=>$demande->demande_Action,
'demande_status'=>$demande->demande_status,
'demande_content'=> $demande->demande_content,
];
} else {
Yii::error($demande->getErrors(), __METHOD__);
throw new ServerErrorHttpException('Une erreur s\'est produite lors de la création. Merci de réessayer.');
}
}
i have error with response: Error : Something went wrong