/mvc/controllers/error
[return to app]1
<?php
2 /**
3 * Requests that end in errors are sent to this controller
4 */
5 class errorController {
6 /**
7 * Changes to the "#error" view
8 */
9 public function __construct() {
10 mvc::$view = (!is::ajax() ? '#error' : '#json');
11 get::$title = 'Error';
12 }
13
14 /**
15 * Handles errors for:
16 * unknownError
17 * notFound - 404
18 * controllerNotDefined - View is working, the controller file or class cannot be accessed
19 * invalidControllerName - View is working, the controller filename or classname is invalid
20 * missingAction - Controller is working, but it is missing the action method inside it
21 * missingView - View cannot be found
22 * redirectEndlessLooping - Endless-redirection safety mechanism gets triggered after 10+ redirects in one
instance
23 *
24 * @param string $method
25 * @param array $args
26 * @return array
27 */
28 public function __call($method, $args) {
29 $errors404 = array('notFound', 'controllerNotDefined', 'invalidControllerName', 'missingAction',
'missingView',
30 'redirectEndlessLooping');
31 $is404 = (in_array($method, $errors404));
32 if ($is404) {
33 get::$title = '404 Error - Not Found';
34 } else {
35 if ($method != 'index') {
36 get::$title = 'Error: ' . str_replace('_', ' ', $method);
37 }
38 $method = 'unknownError';
39 if (is::ajax()) {
40 get::component('error')->log('AJAX Error');
41 } else {
42 get::component('error')->log(get::$title);
43 }
44 }
45 $return = array('errorType' => $method, 'controller' => mvc::$controller, 'action' => mvc::$action,
46 'is404' => $is404);
47 if (is::ajax()) {
48 $return = array('json' => $return);
49 }
50 return $return;
51 }
52 }