Php 在yii2中,API使用GET方法工作,但不使用POST方法
在这里,我使用POSTmethod为它编写了APIForRegisterSchedule,用于使用postman检查API,但如果我使用GET方法而不是PostItWorkin,它将无法与POST方法一起工作Php 在yii2中,API使用GET方法工作,但不使用POST方法,php,yii2,Php,Yii2,在这里,我使用POSTmethod为它编写了APIForRegisterSchedule,用于使用postman检查API,但如果我使用GET方法而不是PostItWorkin,它将无法与POST方法一起工作 public function actionRegister() { $response = []; if (isset($_POST['practiceCode']) && isset($_POST['offic
public function actionRegister() {
$response = [];
if (isset($_POST['practiceCode']) &&
isset($_POST['officeID']) &&
isset($_POST['token']) &&
isset($_POST['workingDays']) &&
isset($_POST['morningStart']) &&
isset($_POST['morningEnd']) &&
isset($_POST['afternoonStart']) &&
isset($_POST['afternoonEnd']) &&
isset($_POST['eveningStart']) &&
isset($_POST['eveningEnd'])) {
$practiceModel = Practice::find()->where(['practiceCode' => $_POST['practiceCode'], 'deleted' => 'N'])->one();
if ($practiceModel != null) {
$officeModel = Office::find()->where(['practiceCode' => $_POST['practiceCode'], 'deleted' => 'N'])->all();
if ($officeModel != null) {
$arrayOffice = Office::find()->where(['id' => $_POST['officeID'], 'deleted' => 'N'])->one();
if($arrayOffice != null) {
$scheduleModel = new Schedule();
$scheduleModel->officeID = $_POST['officeID'];
$scheduleModel->token = $_POST['token'];
$scheduleModel->workingDays = $_POST['workingDays'];
$scheduleModel->morningStart = $_POST['morningStart'];
$scheduleModel->morningEnd = $_POST['morningEnd'];
$scheduleModel->afternoonStart = $_POST['afternoonEnd'];
$scheduleModel->eveningStart = $_POST['eveningStart'];
$scheduleModel->eveningEnd = $_POST['eveningEnd'];
// $scheduleModel->practiceCode = $_POST['practiceCode'];
if ($scheduleModel->save()) {
$response = ['code' => '200',
'result' => 'Success',
'message' => 'Schedule created successfully',
'details' => $scheduleModel->toArray(),
];
} else {
$response = ['code' => '400',
'result' => 'Failure',
'message' => 'Could not Schedule you at this moment'];
}
} else {
$response = ['code' => '400',
'result' => 'Failure',
'message' => 'Specified Office does not exist.',
];
}
} else {
$response = ['code' => '400',
'result' => 'Failure',
'message' => 'Specified practice code Office does not exist.',
];
}
} else {
$response = ['code' => '400',
'result' => 'Failure',
'message' => 'Specified practice code does not exist. ',
];
}
} else {
$response = ['code' => '400',
'result' => 'Failure',
'message' => 'Invalid request/missing parameters',
];
}
\Yii::$app->response->format = 'json';
return $response;
}
出于安全目的,yii 2.0不允许第三方POST请求。例如,在你的情况下,邮递员。要启用POST请求,请将其添加到控制器中:
this->$enableCsrfValidation=false代码>
您可以查看stackoverflow站点,有很多与此相关的主题。请查看:
如需进一步阅读,请查看:
出于安全目的,yii 2.0不允许第三方POST请求。例如,在你的情况下,邮递员。要启用POST请求,请将其添加到控制器中:
this->$enableCsrfValidation=false代码>
您可以查看stackoverflow站点,有很多与此相关的主题。请查看:
如需进一步阅读,请查看:
我已经在控制器中添加了此“public$enableCsrfValidation=false;”我已经在控制器中添加了此“public$enableCsrfValidation=false;”