|
1
|
|
|
<?php |
|
2
|
|
|
namespace backend\components; |
|
3
|
|
|
|
|
4
|
|
|
use Yii; |
|
5
|
|
|
use yii\base\InvalidConfigException; |
|
6
|
|
|
use yii\filters\AccessControl; |
|
7
|
|
|
use yii\web\NotFoundHttpException; |
|
8
|
|
|
use yii\db\ActiveRecord; |
|
9
|
|
|
use yii\filters\VerbFilter; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Site controller |
|
13
|
|
|
*/ |
|
14
|
|
|
class Controller extends \yii\web\Controller |
|
15
|
|
|
{ |
|
16
|
|
|
const FLASH_INFO = 'info'; |
|
17
|
|
|
const FLASH_SUCCESS = 'success'; |
|
18
|
|
|
const FLASH_WARNING = 'warning'; |
|
19
|
|
|
const FLASH_DANGER = 'danger'; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var string | null | ActiveRecord |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $modelClass; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @inheritdoc |
|
28
|
|
|
*/ |
|
29
|
|
|
public function behaviors() |
|
30
|
|
|
{ |
|
31
|
|
|
return [ |
|
32
|
|
|
'access' => [ |
|
33
|
|
|
'class' => AccessControl::class, |
|
34
|
|
|
'rules' => [ |
|
35
|
|
|
[ |
|
36
|
|
|
'allow' => true, |
|
37
|
|
|
'roles' => ['@'], |
|
38
|
|
|
], |
|
39
|
|
|
], |
|
40
|
|
|
], |
|
41
|
|
|
'verbs' => [ |
|
42
|
|
|
'class' => VerbFilter::class, |
|
43
|
|
|
'actions' => [ |
|
44
|
|
|
'delete' => ['POST'], |
|
45
|
|
|
], |
|
46
|
|
|
], |
|
47
|
|
|
]; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Finds the MailerDomain model based on its primary key value. |
|
52
|
|
|
* If the model is not found, a 404 HTTP exception will be thrown. |
|
53
|
|
|
* @param integer | string $id |
|
54
|
|
|
* @return ActiveRecord |
|
55
|
|
|
* @throws InvalidConfigException |
|
56
|
|
|
* @throws NotFoundHttpException |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function findModel($id) |
|
59
|
|
|
{ |
|
60
|
|
|
if ($this->modelClass === null) { |
|
61
|
|
|
throw new InvalidConfigException('The "modelClass" property must be set.'); |
|
62
|
|
|
} |
|
63
|
|
|
if (($model = $this->modelClass::findOne($id)) !== null) { |
|
64
|
|
|
return $model; |
|
|
|
|
|
|
65
|
|
|
} else { |
|
66
|
|
|
throw new NotFoundHttpException('The requested page does not exist.'); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Adds a flash message. |
|
72
|
|
|
* @param string $message |
|
73
|
|
|
* @param string $key |
|
74
|
|
|
* @return $this |
|
75
|
|
|
*/ |
|
76
|
|
|
protected function addFlashMessage($message, $key = self::FLASH_INFO) |
|
77
|
|
|
{ |
|
78
|
|
|
Yii::$app->session |
|
79
|
|
|
->addFlash($key, $message); |
|
|
|
|
|
|
80
|
|
|
return $this; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|