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 | public $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){ |
||
55 | |||
56 | /** |
||
57 | * Perform the startup process for this controller. |
||
58 | * Events that that will be triggered for each controller: |
||
59 | * 1. load components |
||
60 | * 2. perform any logic before calling controller's action(method) |
||
61 | * 3. trigger startup method of loaded components |
||
62 | * |
||
63 | * @return void|Response |
||
64 | */ |
||
65 | public function startupProcess(){ |
||
76 | |||
77 | /** |
||
78 | * Initialization method. |
||
79 | * initialize components and optionally, assign configuration data |
||
80 | * |
||
81 | */ |
||
82 | public function initialize(){ |
||
92 | |||
93 | /** |
||
94 | * load the components by setting the component's name to a controller's property. |
||
95 | * |
||
96 | * @param array $components |
||
97 | */ |
||
98 | public function loadComponents(array $components){ |
||
115 | |||
116 | /** |
||
117 | * triggers component startup methods. |
||
118 | * But, for auth, we are calling authentication and authorization separately |
||
119 | * |
||
120 | * You need to Fire the Components and Controller callbacks in the correct order, |
||
121 | * For example, Authorization depends on form element, so you need to trigger Security first. |
||
122 | * |
||
123 | */ |
||
124 | private function triggerComponents(){ |
||
171 | |||
172 | /** |
||
173 | * show error page |
||
174 | * |
||
175 | * call error action method and set response status code |
||
176 | * This will work as well for ajax call, see how ajax calls are handled in main.js |
||
177 | * |
||
178 | * @param int|string $code |
||
179 | * |
||
180 | */ |
||
181 | public function error($code){ |
||
204 | |||
205 | /** |
||
206 | * Called before the controller action. |
||
207 | * Used to perform logic that needs to happen before each controller action. |
||
208 | * |
||
209 | */ |
||
210 | public function beforeAction(){} |
||
211 | |||
212 | /** |
||
213 | * Magic accessor for model autoloading. |
||
214 | * |
||
215 | * @param string $name Property name |
||
216 | * @return object The model instance |
||
217 | */ |
||
218 | public function __get($name) { |
||
221 | |||
222 | /** |
||
223 | * load model |
||
224 | * It assumes the model's constructor doesn't need parameters for constructor |
||
225 | * |
||
226 | * @param string $model class name |
||
227 | */ |
||
228 | public function loadModel($model){ |
||
229 | return $this->{$model} = new $model(); |
||
230 | } |
||
231 | |||
232 | /** |
||
233 | * forces SSL request |
||
234 | * |
||
235 | * @see core/components/SecurityComponent::secureRequired() |
||
236 | */ |
||
237 | public function forceSSL(){ |
||
241 | } |
||
242 |
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.