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 | * redirector |
||
38 | * |
||
39 | * @var Redirector |
||
40 | */ |
||
41 | public $redirector; |
||
42 | |||
43 | /** |
||
44 | * loaded components |
||
45 | * |
||
46 | * @var array |
||
47 | */ |
||
48 | public $components = []; |
||
49 | |||
50 | /** |
||
51 | * Constructor |
||
52 | * |
||
53 | * @param Request $request |
||
54 | * @param Response $response |
||
55 | */ |
||
56 | public function __construct(Request $request = null, Response $response = null){ |
||
63 | |||
64 | /** |
||
65 | * Perform the startup process for this controller. |
||
66 | * Events that that will be triggered for each controller: |
||
67 | * 1. load components |
||
68 | * 2. perform any logic before calling controller's action(method) |
||
69 | * 3. trigger startup method of loaded components |
||
70 | * |
||
71 | * @return void|Response |
||
72 | */ |
||
73 | public function startupProcess(){ |
||
84 | |||
85 | /** |
||
86 | * Initialization method. |
||
87 | * initialize components and optionally, assign configuration data |
||
88 | * |
||
89 | */ |
||
90 | public function initialize(){ |
||
100 | |||
101 | /** |
||
102 | * load the components by setting the component's name to a controller's property. |
||
103 | * |
||
104 | * @param array $components |
||
105 | */ |
||
106 | public function loadComponents(array $components){ |
||
123 | |||
124 | /** |
||
125 | * triggers component startup methods. |
||
126 | * But, for auth, we are calling authentication and authorization separately |
||
127 | * |
||
128 | * You need to Fire the Components and Controller callbacks in the correct order, |
||
129 | * For example, Authorization depends on form element, so you need to trigger Security first. |
||
130 | * |
||
131 | */ |
||
132 | private function triggerComponents(){ |
||
179 | |||
180 | /** |
||
181 | * show error page |
||
182 | * |
||
183 | * call error action method and set response status code |
||
184 | * This will work as well for ajax call, see how ajax calls are handled in main.js |
||
185 | * |
||
186 | * @param int|string $code |
||
187 | * |
||
188 | */ |
||
189 | public function error($code){ |
||
212 | |||
213 | /** |
||
214 | * Called before the controller action. |
||
215 | * Used to perform logic that needs to happen before each controller action. |
||
216 | * |
||
217 | */ |
||
218 | public function beforeAction(){} |
||
219 | |||
220 | /** |
||
221 | * Magic accessor for model autoloading. |
||
222 | * |
||
223 | * @param string $name Property name |
||
224 | * @return object The model instance |
||
225 | */ |
||
226 | public function __get($name) { |
||
229 | |||
230 | /** |
||
231 | * load model |
||
232 | * It assumes the model's constructor doesn't need parameters for constructor |
||
233 | * |
||
234 | * @param string $model class name |
||
235 | */ |
||
236 | public function loadModel($model){ |
||
237 | $uc_model = ucwords($model); |
||
238 | return $this->{$model} = new $uc_model(); |
||
239 | } |
||
240 | |||
241 | /** |
||
242 | * forces SSL request |
||
243 | * |
||
244 | * @see core/components/SecurityComponent::secureRequired() |
||
245 | */ |
||
246 | public function forceSSL(){ |
||
250 | } |
||
251 |
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.