yiier/yii2-return-url

Keeps current URL in session for login actions so we can return to it if needed.

Installs: 9 161

Dependents: 1

Suggesters: 0

Security: 0

Stars: 10

Watchers: 2

Forks: 6

Open Issues: 0

Type:yii2-extension

v1.1.0 2020-02-17 14:28 UTC

This package is auto-updated.

Last update: 2024-12-18 01:01:26 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

Keeps current URL in session for login actions so we can return to it if needed.

中文说明:登录之后自动跳转登录之前的页面

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist yiier/yii2-return-url "*"

or add

"yiier/yii2-return-url": "*"

to the require section of your composer.json file.

Usage

Method One (方式一,推荐)

you need to include it in config:

return [
    'on beforeAction' => function ($event) {
        Yii::createObject([
            'class' => \yiier\returnUrl\ReturnUrl::class,
            'uniqueIds' => ['site/qrcode', 'site/login', 'site/signup']
        ])->beforeAction();
    },
    'components' => [
    ]
];

Method Two (方式二)

In your controller add ReturnUrl filter to behaviors:

public function behaviors()
{
    return [
        'returnUrl' => [
            'class' => 'yiier\returnUrl\ReturnUrl',
            'uniqueIds' => ['site/qrcode', 'site/login', 'user/security/auth'] // 过滤掉不需要的 controller/action
        ],
    ];
}

For access to previously visited url:

Yii::$app->user->getReturnUrl();