Skip to content

Is a component for configuration of redirects from controller actions to routes or previous page

License

Notifications You must be signed in to change notification settings

black-lamp/yii2-redirect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Redirect behavior for Yii2

Is a component for configuration of redirects from controller actions to routes or previous page

Latest Stable Version Latest Unstable Version License

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.

About

Is a component for configuration of redirects from controller actions to routes or previous page

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages