From 5d46a8b24d19450bedb3eee8e7650023e971a44b Mon Sep 17 00:00:00 2001 From: William Date: Sat, 15 Jan 2022 11:26:02 +0100 Subject: [PATCH] Commit --- app/class/DatabaseHandler.php | 23 ---------------------- app/class/Template.php | 24 ----------------------- app/common.php | 9 --------- app/core/ApiController.php | 7 +++++++ app/core/Controller.php | 20 +++++++++++++++++++ app/core/Database.php | 31 ++++++++++++++++++++++++++++++ app/core/Session.php | 14 ++++++++++++++ app/inc.php | 9 +++++++++ app/model/Index.php | 8 ++++++++ app/view/index.php | 3 +++ app/{ => view}/template/footer.php | 0 app/{ => view}/template/header.php | 2 +- public/example.php | 15 --------------- public/index.php | 21 +++++++++++--------- public/login.php | 25 ------------------------ public/logout.php | 16 --------------- public/subdir/index.php | 15 --------------- 17 files changed, 105 insertions(+), 137 deletions(-) delete mode 100644 app/class/DatabaseHandler.php delete mode 100644 app/class/Template.php delete mode 100644 app/common.php create mode 100644 app/core/ApiController.php create mode 100644 app/core/Controller.php create mode 100644 app/core/Database.php create mode 100644 app/core/Session.php create mode 100644 app/inc.php create mode 100644 app/model/Index.php create mode 100644 app/view/index.php rename app/{ => view}/template/footer.php (100%) rename app/{ => view}/template/header.php (97%) delete mode 100644 public/example.php delete mode 100644 public/login.php delete mode 100644 public/logout.php delete mode 100644 public/subdir/index.php diff --git a/app/class/DatabaseHandler.php b/app/class/DatabaseHandler.php deleted file mode 100644 index dbbda55..0000000 --- a/app/class/DatabaseHandler.php +++ /dev/null @@ -1,23 +0,0 @@ - true, - ]; - try { - return new PDO($dsn, $user, $pass, $options); - } catch (PDOException $e) { - throw new PDOException($e->getMessage(), (int)$e->getCode()); - } - } -} \ No newline at end of file diff --git a/app/class/Template.php b/app/class/Template.php deleted file mode 100644 index 913d6e3..0000000 --- a/app/class/Template.php +++ /dev/null @@ -1,24 +0,0 @@ - 1)) { - $url = htmlspecialchars($url . '/'); - } - - - //FUUUUUCKKK - echo($_SERVER['DOCUMENT_ROOT'] . ' ' . __DIR__); - die(); - return($url.$path); - } - - public function render($name): void - { - require(__DIR__ . '/../template/' . $name . '.php'); - } -} \ No newline at end of file diff --git a/app/common.php b/app/common.php deleted file mode 100644 index 62b6aa6..0000000 --- a/app/common.php +++ /dev/null @@ -1,9 +0,0 @@ -dbh = $this->connectWithMySQL(); + } catch (PDOException $e) { + throw new PDOException($e->getMessage(), (int)$e->getCode()); + } + } + + private function connectWithMySQL(): object + { + $dsn = "mysql:host=$this->host;dbname=$this->db;charset=$this->charset"; + $options = [ + PDO::ATTR_PERSISTENT => true, + ]; + return new PDO($dsn, $this->user, $this->pass, $options); + } +} \ No newline at end of file diff --git a/app/core/Session.php b/app/core/Session.php new file mode 100644 index 0000000..d3351a4 --- /dev/null +++ b/app/core/Session.php @@ -0,0 +1,14 @@ +Hello world +

This is a message from the view

+

\ No newline at end of file diff --git a/app/template/footer.php b/app/view/template/footer.php similarity index 100% rename from app/template/footer.php rename to app/view/template/footer.php diff --git a/app/template/header.php b/app/view/template/header.php similarity index 97% rename from app/template/header.php rename to app/view/template/header.php index e86d03c..66ff18d 100644 --- a/app/template/header.php +++ b/app/view/template/header.php @@ -4,7 +4,7 @@ - <?=htmlspecialchars($this->params["title"]);?> – Stafett for livet + <?=htmlspecialchars($title);?> – Stafett for livet diff --git a/public/example.php b/public/example.php deleted file mode 100644 index 2ab89ac..0000000 --- a/public/example.php +++ /dev/null @@ -1,15 +0,0 @@ -render("header"); -?> - -

Eksempel side

-

Dette er en eksempel side

- -render("footer"); -?> \ No newline at end of file diff --git a/public/index.php b/public/index.php index f34af34..cac92ce 100644 --- a/public/index.php +++ b/public/index.php @@ -1,13 +1,16 @@ render("header"); -?> +// Instantiate a new controller +$contr = new Controller; -

Forsida!

-

Vi planlegger for Kreftforeningens Stafett for livet Kristiansand i juni 2021 og håper du blir med.

-

Stafettene i 2021 tilpasses nasjonale og lokale smittevernsråd, og det vil være lokale variasjoner i hvordan stafettene gjennomføres. Men målet er likt: Vi skal hedre fighterne, vise vår støtte, minnes de vi har mistet, gi håp og feire livet.

+// Grab the model +$model = $contr->model('Index'); -render("footer"); -?> \ No newline at end of file +// Perform database task with model +$username = $model->getUsername(); + +// Display view with retrieved data +$contr->view('index', [ + "data" => $username +]); \ No newline at end of file diff --git a/public/login.php b/public/login.php deleted file mode 100644 index c61f294..0000000 --- a/public/login.php +++ /dev/null @@ -1,25 +0,0 @@ -render("header"); -?> - -

Logg inn

-

Fyll ut legitimasjonen din for å logge inn.

- -
- -
- -
- -
- -
-
- -
- -render("footer"); -?> \ No newline at end of file diff --git a/public/logout.php b/public/logout.php deleted file mode 100644 index f196f4e..0000000 --- a/public/logout.php +++ /dev/null @@ -1,16 +0,0 @@ - \ No newline at end of file diff --git a/public/subdir/index.php b/public/subdir/index.php deleted file mode 100644 index 532b273..0000000 --- a/public/subdir/index.php +++ /dev/null @@ -1,15 +0,0 @@ -render("header"); -?> - -

Eksempel side

-

Dette er en eksempel side

- -render("footer"); -?> \ No newline at end of file