Is a component for configuration of redirects from controller actions to routes or previous page
Run command
composer require black-lamp/yii2-redirect
or add
"black-lamp/yii2-redirect": "dev-master"
to the require section of your composer.json.
Add behavior to your controller
public function behaviors()
{
return [
'redirect' => [
'class' => \bl\redirect\RedirectBehavior::class,
'actions' => [
]
],
];
}
and configure redirects in the actions
array
// ...
'class' => \bl\redirect\RedirectBehavior::class,
'actions' => [
'register' => ['/news'],
'send-request' => ['/user'],
// ...
]
array key it's a action ID and the value of the array it's a route to redirect.
If you leave route empty like this
'actions' => [
'register' => [],
// ...
]
action will be redirected to request referrer.
If referrer is empty - action will be redirected to route from \yii\web\User::getReturnUrl()
.
You can change this route if you use \yii\web\User::setReturnUrl()
method.