diff options
author | Freya Murphy <freya@freyacat.org> | 2024-09-18 14:14:53 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2024-09-18 14:48:54 -0400 |
commit | 1f9024763d9224c4cd9a181bac27e6b9f12ad672 (patch) | |
tree | 00f827470dad9aa2692483acbdef9502c1a464d3 /src/web/core/controller.php | |
parent | fix rss (diff) | |
download | website-1f9024763d9224c4cd9a181bac27e6b9f12ad672.tar.gz website-1f9024763d9224c4cd9a181bac27e6b9f12ad672.tar.bz2 website-1f9024763d9224c4cd9a181bac27e6b9f12ad672.zip |
refactor
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(); + } + +} |