black-lamp / yii2-redirect
Is a component for configuration of redirects from controller actions to routes or previous page
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- yiisoft/yii2: ^2.0.4
This package is not auto-updated.
Last update: 2024-11-18 16:00:06 UTC
README
Is a component for configuration of redirects from controller actions to routes or previous page
Installation
Run command
composer require black-lamp/yii2-redirect
or add
"black-lamp/yii2-redirect": "dev-master"
to the require section of your composer.json.
Using
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.