-
Notifications
You must be signed in to change notification settings - Fork 6
/
ReturnUrl.php
53 lines (46 loc) · 1.01 KB
/
ReturnUrl.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/**
* author : forecho <[email protected]>
* createTime : 2016/3/16 10:14
* description:
*/
namespace yiier\returnUrl;
use Yii;
use yii\base\Behavior;
use yii\web\Controller;
class ReturnUrl extends Behavior
{
/**
* @var array
*/
public $uniqueIds = ['site/login'];
public function events()
{
return [
Controller::EVENT_BEFORE_ACTION => 'beforeAction',
];
}
/**
* @return bool
* @throws \yii\base\InvalidConfigException
*/
public function beforeAction()
{
if (Yii::$app->user->isGuest) {
if (!(Yii::$app->request->getIsAjax() || $this->isValidate())) {
Yii::$app->user->setReturnUrl(Yii::$app->request->getUrl());
}
}
return true;
}
/**
* @return bool
*/
private function isValidate()
{
if (in_array(Yii::$app->controller->action->uniqueId, $this->uniqueIds)) {
return true;
}
return false;
}
}