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 <?php
class Controller class App
{ {
public function __construct()
{
$config = require __DIR__ . '/../config.php';
$this->config = $config;
}
public function model(string $model): object public function model(string $model): object
{ {
// Require model file // 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'; require __DIR__ . '/core/' . $class_name . '.php';
}); });
// Define global CONFIG constant. // God mode class that instantiates many other classes... or something like that
define("CONFIG", return new App();
require __DIR__ . '/config.php'
);

View File

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

View File

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

View File

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

View File

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

View File

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