I’m developing a REST controller and a web backend with the basic template.
I’m trying to post some values via (Firefox, RESTED Client), but I’m having a very weird performances. Sometimes, the post variables are catched, but in some others, they simply are not being catched, more if I check the $_POST
variable and it is empty too.
It isn’t related, i guess, with the urlManager because as I said, the same URLs sometimes work, sometimes don’t work.
What do I do?:
On each function I need to check the access, I call inside $this->checkAccess('the-url');
and inside the checkAccess method:
public function checkAccess($action, $model = null, $params = array())
{
if (Yii::$app->request->isPost) {
$body = Yii::$app->request->post();
Yii::debug(var_export($body, true)); // empty sometimes, the data some others.
if ($action !== 'login' || $action !== "index") {
if (!isset($body['auth_key'])) {
throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
} elseif (($model = User::findIdentityByAccessToken($body['auth_key'])) === null) {
throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
}
}
} else {
if ($action !== 'login' || $action !== "index") {
$body = Yii::$app->request->get();
if (!Yii::$app->request->get("auth_key")) {
throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
} elseif (($model = User::findIdentityByAccessToken(Yii::$app->request->get("auth_key"))) === null) {
throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
}
}
}
}
If I use rawBody, the data is printed as string, just like the URL query string.
I have to try a lot of times before the post parameters are finally catched.