Answer the question
In order to leave comments, you need to log in
Why doesn't ActionFilter render the correct file?
Here I created a filter, but it does not work, it just displays the main page (/site/index)
class FilterBannedIp extends ActionFilter {
public function beforeAction($action) {
$bannedIp = BannedIp::findByIp(Yii::$app->request->getUserIP());
// die(var_dump(Yii::$app->request->getUserIP()));
// die($bannedIp->ip);
if ($bannedIp && $bannedIp->isBanned(Yii::$app->request->getUserIP())) {
if (Yii::$app->request->isAjax) {
return 'Error: Ваш IP заблокирован';
} else {
return $action->controller->render('/site/banned_ip', [
'bannedIp' => $bannedIp,
]);
}
}
return parent::beforeAction($action);
}
}
Answer the question
In order to leave comments, you need to log in
Because the task of the filter is to check whether there is access to the action or not.
It can return true or false, it's up to the controller to render the response.
Inside beforeAction, you can throw an exception that will catch errorHandler, but there in errorHandler->errorAction you can render an error
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question