1
0

view.php 487 B

1234567891011121314151617181920212223
  1. <?php
  2. class View {
  3. protected static $included = [];
  4. public static function include($view, $params = []) {
  5. $view_path = ROOT_DIR . "/views/" . $view . ".php";
  6. if(file_exists($view_path)) {
  7. self::$included[] = $view;
  8. extract($params);
  9. require $view_path;
  10. }
  11. else {
  12. throw new Exception("View \"$view\" not found");
  13. }
  14. }
  15. public static function includeOnce($view, $params = []) {
  16. if(in_array($view, self::$included)) return;
  17. self::include($view, $params);
  18. }
  19. }