/mvc/controllers/error
[return to app]1
<?php
/**
* Requests that end in errors are sent to this controller
*/
class errorController {
/**
* Changes to the "#error" view
*/
public function __construct() {
mvc::$view = (!is::ajax() ? '#error' : '#json');
get::$title = 'Error';
}
/**
* Handles errors for:
* unknownError
* notFound - 404
* controllerNotDefined - View is working, the controller file or class cannot be accessed
* invalidControllerName - View is working, the controller filename or classname is invalid
* missingAction - Controller is working, but it is missing the action method inside it
* missingView - View cannot be found
* redirectEndlessLooping - Endless-redirection safety mechanism gets triggered after 10+ redirects in one
instance
*
* @param string $method
* @param array $args
* @return array
*/
public function __call($method, $args) {
$errors404 = array('notFound', 'controllerNotDefined', 'invalidControllerName', 'missingAction',
'missingView',
'redirectEndlessLooping');
$is404 = (in_array($method, $errors404));
if ($is404) {
get::$title = '404 Error - Not Found';
} else {
if ($method != 'index') {
get::$title = 'Error: ' . str_replace('_', ' ', $method);
}
$method = 'unknownError';
if (is::ajax()) {
get::component('error')->log('AJAX Error');
} else {
get::component('error')->log(get::$title);
}
}
$return = array('errorType' => $method, 'controller' => mvc::$controller, 'action' => mvc::$action,
'is404' => $is404);
if (is::ajax()) {
$return = array('json' => $return);
}
return $return;
}
}

