1 | <?php |
||
23 | class BaseAction extends Action |
||
24 | { |
||
25 | /** |
||
26 | * @var callable a PHP callable that will be called to return the model corresponding |
||
27 | * to the specified primary key value. |
||
28 | * The signature of the callable should be: |
||
29 | * |
||
30 | * ```php |
||
31 | * function ($params) { |
||
32 | * // $params is the params from request |
||
33 | * } |
||
34 | * ``` |
||
35 | * |
||
36 | * The callable should return the model found. Otherwise the not found exception will be thrown. |
||
37 | */ |
||
38 | public $findModel; |
||
39 | |||
40 | /** |
||
41 | * @var mixed $redirectTo the route to redirect to. It can be one of the followings: |
||
42 | * |
||
43 | * - A PHP callable. The callable will be executed to get route. The signature of the callable |
||
44 | * should be: |
||
45 | * |
||
46 | * ```php |
||
47 | * function ($model){ |
||
48 | * // $model is the model object. |
||
49 | * } |
||
50 | * ``` |
||
51 | * |
||
52 | * The callable should return route/url to redirect to. |
||
53 | * |
||
54 | * - An array. Treated as route. |
||
55 | * - A string. Treated as url. |
||
56 | */ |
||
57 | public $redirectTo = null; |
||
58 | |||
59 | /** |
||
60 | * @var string the message shown after success completed operation. |
||
61 | */ |
||
62 | public $successMessage = ''; |
||
63 | |||
64 | /** |
||
65 | * @var string the message shown after completed operation with error. |
||
66 | */ |
||
67 | public $errorMessage = ''; |
||
68 | |||
69 | /** |
||
70 | * @var string the Session object or the application component ID of the session object. |
||
71 | */ |
||
72 | public $session = 'session'; |
||
73 | |||
74 | /** |
||
75 | * @var \yii\web\Controller the controller that owns this action |
||
76 | */ |
||
77 | public $controller; |
||
78 | |||
79 | /** |
||
80 | * If the data model is not found, an exception is thrown HTTP 404 |
||
81 | * @param mixed $id |
||
82 | * @return ActiveRecord |
||
83 | * @throws NotFoundHttpException |
||
84 | */ |
||
85 | 33 | public function getModel($id) |
|
98 | |||
99 | |||
100 | /** |
||
101 | * Redirect to route passed as param |
||
102 | * @param ActiveRecord $model |
||
103 | * @return mixed |
||
104 | */ |
||
105 | 21 | public function redirect(ActiveRecord $model = null) |
|
123 | |||
124 | /** |
||
125 | * Adds flash message about success completed operation. |
||
126 | */ |
||
127 | 12 | public function addSuccessFlash() |
|
135 | |||
136 | /** |
||
137 | * Adds flash message if completed operation with error. |
||
138 | */ |
||
139 | 9 | public function addErrorFlash() |
|
147 | } |
||
148 |