Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/black-lamp/yii2-redirect
Is a component for configuration of redirects from controller actions to routes or previous page
https://github.com/black-lamp/yii2-redirect
black-lamp php yii-extension yii2
Last synced: about 2 months ago
JSON representation
Is a component for configuration of redirects from controller actions to routes or previous page
- Host: GitHub
- URL: https://github.com/black-lamp/yii2-redirect
- Owner: black-lamp
- License: bsd-3-clause
- Created: 2017-02-07T18:25:20.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-02-07T22:03:57.000Z (almost 8 years ago)
- Last Synced: 2024-03-26T00:39:12.804Z (10 months ago)
- Topics: black-lamp, php, yii-extension, yii2
- Language: PHP
- Size: 3.91 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Redirect behavior for Yii2
==========================
Is a component for configuration of redirects from controller actions to routes or previous page[![Latest Stable Version](https://poser.pugx.org/black-lamp/yii2-redirect/v/stable)](https://packagist.org/packages/black-lamp/yii2-redirect)
[![Latest Unstable Version](https://poser.pugx.org/black-lamp/yii2-redirect/v/unstable)](https://packagist.org/packages/black-lamp/yii2-redirect)
[![License](https://poser.pugx.org/black-lamp/yii2-redirect/license)](https://packagist.org/packages/black-lamp/yii2-redirect)Installation
------------
Run command
```
composer require black-lamp/yii2-redirect
```
or add
```json
"black-lamp/yii2-redirect": "dev-master"
```
to the require section of your composer.json.Using
-----
Add behavior to your controller
```php
public function behaviors()
{
return [
'redirect' => [
'class' => \bl\redirect\RedirectBehavior::class,
'actions' => [
]
],
];
}
```
and configure redirects in the `actions` array
```php
// ...
'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
```php
'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.