1 | <?php |
||
13 | class Controller { |
||
|
|||
14 | |||
15 | /** |
||
16 | * view |
||
17 | * |
||
18 | * @var View |
||
19 | */ |
||
20 | protected $view; |
||
21 | |||
22 | /** |
||
23 | * request |
||
24 | * |
||
25 | * @var Request |
||
26 | */ |
||
27 | public $request; |
||
28 | |||
29 | /** |
||
30 | * response |
||
31 | * |
||
32 | * @var Response |
||
33 | */ |
||
34 | protected $response; |
||
35 | |||
36 | /** |
||
37 | * loaded components |
||
38 | * |
||
39 | * @var array |
||
40 | */ |
||
41 | public $components = []; |
||
42 | |||
43 | /** |
||
44 | * Constructor |
||
45 | * |
||
46 | * @param Request $request |
||
47 | * @param Response $response |
||
48 | */ |
||
49 | public function __construct(Request $request = null, Response $response = null){ |
||
66 | |||
67 | /** |
||
68 | * triggers component startup methods. |
||
69 | * But, for auth, we are calling authentication and authorization separately |
||
70 | * |
||
71 | * You need to Fire the Components and Controller callbacks in the correct order, |
||
72 | * For example, Authorization depends on form element, so you need to trigger Security first. |
||
73 | * |
||
74 | */ |
||
75 | public function triggerComponents(){ |
||
118 | |||
119 | /** |
||
120 | * Initialization method. |
||
121 | * initialize components and optionally, assign configuration data |
||
122 | * |
||
123 | */ |
||
124 | public function initialize(){ |
||
134 | |||
135 | /** |
||
136 | * load the components by setting the component's name to a controller's property. |
||
137 | * |
||
138 | * @param array $components |
||
139 | */ |
||
140 | public function loadComponents(array $components){ |
||
157 | |||
158 | /** |
||
159 | * show error page |
||
160 | * |
||
161 | * call error action method and set response status code |
||
162 | * This will work as well for ajax call, see how ajax calls are handled in main.js |
||
163 | * |
||
164 | * @param int|string $code |
||
165 | * |
||
166 | */ |
||
167 | public function error($code){ |
||
189 | |||
190 | /** |
||
191 | * Called before the controller action. |
||
192 | * Used to perform logic that needs to happen before each controller action. |
||
193 | * |
||
194 | */ |
||
195 | public function beforeAction(){} |
||
196 | |||
197 | /** |
||
198 | * Magic accessor for model autoloading. |
||
199 | * |
||
200 | * @param string $name Property name |
||
201 | * @return object The model instance |
||
202 | */ |
||
203 | public function __get($name) { |
||
206 | |||
207 | /** |
||
208 | * load model |
||
209 | * It assumes the model's constructor doesn't need parameters for constructor |
||
210 | * |
||
211 | * @param string $model class name |
||
212 | */ |
||
213 | public function loadModel($model){ |
||
214 | return $this->{$model} = new $model(); |
||
215 | } |
||
216 | |||
217 | /** |
||
218 | * forces SSL request |
||
219 | * |
||
220 | * @see core/components/SecurityComponent::secureRequired() |
||
221 | */ |
||
222 | public function forceSSL(){ |
||
226 | } |
||
227 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.