summaryrefslogtreecommitdiff
path: root/src/web/core/_controller.php
blob: 1da5a9675a7bb811e0037a615dc2cc2ce68900d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php /* Copyright (c) 2024 Freya Murphy */
abstract class Controller {

	// the main model
	public Main_model $main;

	// the loader
	public Loader $load;

	/**
	 * Creates a constructor
	 * @param Loader $load - the website loaded object
	 */
	function __construct($load) {
		$this->load = $load;
		$this->main = $this->load->model('main');

		$this->load->lang();
		$info = $this->main->info;
		$app = $info['app'];
		if ($app) {
			$this->load->app_lang($app);
		}
	}

	public function index(): void {}

	public function redirect(string $link): void {
		header('Location: '. $link, true, 301);
		die();
	}

    /**
     * @param array<int,mixed> $data
     */
    protected function view(string $__name, array $data = array()): void {
		$__root = $GLOBALS['webroot'];
		$__path = $__root . '/_views/' . $__name . '.php';
		if (is_file($__path)) {
			extract($data);
			require($__path);
			return;
		}
	}

    protected function error(int $code): void {
		$_GET['code'] = $code;
		$this->main->info['app'] = 'error';
		$error_controller = $this->load->controller('error');
		$error_controller->index();
		die();
	}

}