Simple yii2 redirect component.
The preferred way to install this extension is through composer.
Either run
$ composer require bahirul/yii2-redirect
or add
"bahirul/yii2-redirect": "^0.0.1"
to the require
section of your composer.json
file.
Configure application components
as follows
return [
//...
'components' => [
//...
'redirect' => [
'class' => 'bahirul\yii2\Redirect',
],
],
];
Use in your controller action
return Yii::$app->redirect->to($url)->go(); //redirect only
return Yii::$app->redirect->to($url)->flash($flash_name, $flash_message)->go(); //redirect with flash message
return Yii::$app->redirect->prev()->go(); //redirect to previous page or home page (if previous page is null)
return Yii::$app->redirect->login()->go(); //redirect to login page