Attempting to encode json and receive 400: Bad Request
in yii2
. I am trying to encode in Rest client but it is not working properly.
i think 400 have nothing to do with json_encode
google "yii2 csrf" for more information.
public function actionRegister()
{
// is not safe
Yii::$app->controller->enableCsrfValidation = false;
// set response header
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$model = new TblUserRegistration();
$username = $_POST['username'];
return $username;
}
or add scrf in view: form:
meta:
= Html::csrfMetaTags() ?>