diff --git a/application/controllers/error.php b/application/controllers/error.php index 99d72f7..a1d87f2 100644 --- a/application/controllers/error.php +++ b/application/controllers/error.php @@ -2,15 +2,30 @@ class Error extends Controller { - function index() - { - $this->error404(); + function index($segments){ + return $this->error($this->getMessage($segments)); } - - function error404() - { - echo '

404 Error

'; - echo '

Looks like this page doesn\'t exist

'; + + function getMessage($segments){ + if(is_array($segments)){ + $segments = $segments[0]; + } + + return $segments; + } + + function error($segments="Error!"){ + if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { + return json_encode(array( + 'success' => false, + 'data' => array(), + 'message'=> utf8_encode($segments) + )); + } + else{ + return utf8_decode("

{$segments}

"); + } + } }