PageRenderTime 52ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/core/template_core.php

https://github.com/nickbarth/PHP-Tofu
PHP | 66 lines | 49 code | 10 blank | 7 comment | 7 complexity | 747ed01a57baefd70b6fc1c178a17bc0 MD5 | raw file
  1. <?php
  2. class Template
  3. {
  4. public static function render($vars, $displayContents = true)
  5. {
  6. // Get Templating Vars
  7. extract($vars, EXTR_SKIP);
  8. // Include Helper Functions
  9. require(BASEPATH.'/app/helpers/template.php');
  10. // Render View File
  11. ob_start();
  12. include(BASEPATH.'/app/views/'.Routes::getController().'/'.Routes::getMethod().'.php');
  13. $contents = ob_get_contents();
  14. ob_end_clean();
  15. // Render Layout File
  16. ob_start();
  17. include(BASEPATH.'/app/views/layouts/'.Routes::getController().'.php');
  18. $view = ob_get_contents();
  19. ob_end_clean();
  20. foreach($templates as $key => $value)
  21. $view = str_ireplace($key, $value, $view);
  22. // Render View
  23. if ($displayContents)
  24. print $view;
  25. return $view;
  26. }
  27. public static function handleError($errno, $errstr, $errfile, $errline)
  28. {
  29. print $errstr;
  30. // Set Error Message
  31. if (Registry::getDebugMode())
  32. $errorMessage = 'Error Number '.$errno.'. "'.$errstr.'" on '.
  33. 'line '.$errline.' in file "'.$errfile.'"';
  34. else $errorMessage = $errstr;
  35. // Display Error File
  36. $file = BASEPATH.'/app/views/error.php';
  37. if (file_exists($file))
  38. {
  39. include_once(BASEPATH.'/app/helpers/template.php');
  40. ob_start();
  41. include($file);
  42. $contents = ob_get_contents();
  43. ob_end_clean();
  44. foreach($templates as $key => $value)
  45. $view = str_ireplace($key, $value, $view);
  46. print $contents;
  47. } else print 'Error template not found';
  48. exit;
  49. }
  50. public static function handleException($exception)
  51. {
  52. if (Registry::getDebugMode())
  53. trigger_error('Exception: '.$exception->getMessage());
  54. else trigger_error('Internal Server Error');
  55. }
  56. }