Answer the question
In order to leave comments, you need to log in
Yii2 - how to change 403 error message etc.?
How can I change this message?
That's how nothing changes
public function behaviors() {
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'allow' => true,
'roles' => ['admin'],
'denyCallback' => function ($rule, $action) {
throw new ForbiddenHttpException('У Вас нет доступа');
},
],
],
],
];
}
Answer the question
In order to leave comments, you need to log in
Have a look at SiteController.php . There is a method there:
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
...
];
}
'error' => [
'class' => 'yii\web\ErrorAction',
],
Дополню своим ответом.
При использовании таких настроек в SiteController.php у меня появляется код ошибки 500
Это происходит, когда у пользователя нет роли admin.
public function behaviors() {
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'allow' => true,
'roles' => ['admin']
],
],
],
];
}
/**
* {@inheritdoc}
*/
public function actions()
{
return [
'error' => [
'class' => ErrorAction::class,
// Тут можно добавить свой шаблон.
// Или ничего не указывать, при этом будет использоваться тот, который прописан в 'errorHandler'
'view' => 'site/error',
'layout' => 'error'
]
];
}
public function behaviors() {
return [
'access' => [
'class' => AccessControl::className(),
'except' => ['error'],
'rules' => [
[
'allow' => true,
'roles' => ['admin']
],
],
],
];
}
public function behaviors() {
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'actions' => ['error'],
'allow' => true,
],
[
'allow' => true,
'roles' => ['admin']
],
],
],
];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question