This commit is contained in:
William 2022-01-19 19:50:54 +01:00
parent cf19bb3bd5
commit 550a64f57e
9 changed files with 27 additions and 56 deletions

View File

@ -1,7 +0,0 @@
<?php
// Extended controller for RESTful APIs
class ApiController extends Controller
{
// TODO: ...
}

View File

@ -1,7 +1,13 @@
<?php
class Controller
class App
{
public function __construct()
{
$config = require __DIR__ . '/../config.php';
$this->config = $config;
}
public function model(string $model): object
{
// Require model file

View File

@ -1,9 +0,0 @@
<?php
// Provide user feedback by flashing a message on the next request. This is usually combined with a layout template that does this.
class Flash extends Session {
public function add(): void
{
// TODO: ...
}
}

View File

@ -17,7 +17,5 @@ spl_autoload_register(function ($class_name) {
require __DIR__ . '/core/' . $class_name . '.php';
});
// Define global CONFIG constant.
define("CONFIG",
require __DIR__ . '/config.php'
);
// God mode class that instantiates many other classes... or something like that
return new App();

View File

@ -1,7 +1,3 @@
<?php $this->view('template/header', ['title' => $title]); ?>
<h1>Velkommen til forsida!</h1>
<p>Ting fungerer noen ganger.</p>
<p><?=$data?></p>
<?php $this->view('template/footer'); ?>
<p><?=$data?></p>

View File

@ -1,5 +1,3 @@
<?php $this->view('template/header', ['title' => $title]); ?>
<h1>Logg inn</h1>
<p>Fyll inn påloggingsinformasjonen din.</p>
<form method="post">
@ -13,6 +11,4 @@
<br>
<br>
<input type="submit" value="Bekreft">
</form>
<?php $this->view('template/footer'); ?>
</form>

View File

@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?=htmlspecialchars($title);?> Stafett for livet</title>
<link rel="stylesheet" href="<?=CONFIG['root_url']?>/static/style/main.css">
<link rel="stylesheet" href="<?=$this->config['root_url']?>/static/style/main.css">
<body>
<div id="header">
@ -18,7 +18,7 @@
<div id="menu">
<small>
<span>Ikke pålogget</span>
<a href="<?=CONFIG['root_url']?>/login.php">Logg inn</a>
<a href="<?=$this->config['root_url']?>/login.php">Logg inn</a>
</small>
</div>
@ -28,9 +28,9 @@
<div id="nav">
<ul>
<li><a href="<?=CONFIG['root_url']?>/index.php">Forside</a></li>
<li><a href="<?=CONFIG['root_url']?>/login.php">Logg inn</a></li>
<li><a href="<?=CONFIG['root_url']?>">Eksempel</a></li>
<li><a href="<?=$this->config['root_url']?>/index.php">Forside</a></li>
<li><a href="<?=$this->config['root_url']?>/login.php">Logg inn</a></li>
<li><a href="<?=$this->config['root_url']?>">Eksempel</a></li>
</ul>
</div>

View File

@ -1,17 +1,10 @@
<?php
require("../app/inc.php");
$app = require("../app/inc.php");
// Instantiate a new controller
$contr = new Controller;
$model = $app->model('Index');
// Grab the model
$model = $contr->model('Index');
// Perform database task with model
$username = $model->getUsername();
// Display view with retrieved data
$contr->view('index', [
"title" => "Forside",
"data" => $username
]);
$app->view('template/header', ["title" => "Forside"]);
$app->view('index', [
"data" => $model->getUsername()
]);
$app->view('template/footer');

View File

@ -1,8 +1,6 @@
<?php
require("../app/inc.php");
$app = require("../app/inc.php");
$contr = new Controller;
$contr->view('login', [
"title" => "Logg inn",
]);
$app->view('template/header', ["title" => "Logg inn"]);
$app->view('login');
$app->view('template/footer');