error.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. * First, import the relevant Lithium core classes.
  4. */
  5. use \lithium\core\ErrorHandler;
  6. use \lithium\analysis\Logger;
  7. use lithium\action\Response;
  8. use lithium\net\http\Media;
  9. /**
  10. * Then, set up a basic logging configuration that will write to a file.
  11. */
  12. Logger::config(array(
  13. 'error' => array('adapter' => 'File')
  14. ));
  15. ErrorHandler::apply('lithium\action\Dispatcher::run', array(), function($info, $params) {
  16. $response = new Response(array('request' => $params['request']));
  17. $message = "/(^Template not found|^Controller '\w+' not found|^Action '\w+' not found)/";
  18. $template = (preg_match($message, $info['message'])) ? '404' : '500';
  19. Logger::write('error', "{$info['file']} : {$info['line']} : {$info['message']}");
  20. switch($template){
  21. case '500':
  22. debug($info);die;
  23. break;
  24. }
  25. Media::render($response, compact('info', 'params'), array(
  26. 'controller' => 'errors',
  27. 'template' => $template,
  28. 'layout' => 'default',
  29. 'request' => $params['request']
  30. ));
  31. return $response;
  32. });