diff options
Diffstat (limited to 'src/web/core/controller.php')
-rw-r--r-- | src/web/core/controller.php | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/web/core/controller.php b/src/web/core/controller.php new file mode 100644 index 0000000..340bbb1 --- /dev/null +++ b/src/web/core/controller.php @@ -0,0 +1,43 @@ +<?php /* Copyright (c) 2024 Freya Murphy */ + +abstract class Controller extends Component { + + /** + * Default index for a app, empty + */ + public function index(): void {} + + /** + * Redirectes to a link + */ + public function redirect(string $link): void + { + header('Location: '. $link, true, 301); + die(); + } + + /** + * Lodas a view + */ + protected function view(string $__name, array $data = array()): void + { + $__path = WEB_ROOT . '/_views/' . $__name . '.php'; + if (is_file($__path)) { + extract($data); + require($__path); + return; + } + } + + /** + * Loads a erorr page with a given + * error code + */ + protected function error(int $code): void + { + $error_controller = $this->load_controller('error'); + $error_controller->code($code); + die(); + } + +} |