From 0aa067b783ec3ba374380b82612eb876634c78f8 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 1 Apr 2021 13:27:08 +0300 Subject: Made index.php a router and added the basis of landing view and controller --- src/controllers/LandingController.php | 9 +++++++++ src/index.php | 28 +++++++++++++++++++--------- src/models/DB.php | 1 - src/views/landing.php | 7 +++++++ 4 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 src/controllers/LandingController.php create mode 100644 src/views/landing.php (limited to 'src') diff --git a/src/controllers/LandingController.php b/src/controllers/LandingController.php new file mode 100644 index 0000000..80e0b5b --- /dev/null +++ b/src/controllers/LandingController.php @@ -0,0 +1,9 @@ + -

Hello World!

$obj) { - echo "{$obj->id} {$obj->title}
"; - } - echo "
"; +include_once("controllers/LandingController.php"); + +/* The landing page practically acts as our page router + * Thanks https://www.taniarascia.com/the-simplest-php-router/ + */ + +$landingController = new LandingController(); + +$request = $_SERVER['REQUEST_URI']; + +switch ($request) { + case "": + case "/": + $landingController->invoke(); + break; + default: + http_response_code(404); + break; +} ?> diff --git a/src/models/DB.php b/src/models/DB.php index 9fd705c..8174831 100644 --- a/src/models/DB.php +++ b/src/models/DB.php @@ -71,7 +71,6 @@ class DB { $query = rtrim($query, ", "); $query .= ");"; - echo $query; try { $this->connection->exec($query); diff --git a/src/views/landing.php b/src/views/landing.php new file mode 100644 index 0000000..06e32a5 --- /dev/null +++ b/src/views/landing.php @@ -0,0 +1,7 @@ +

Landing page!

+ +id} {$job->title}
"; + } +?> -- cgit v1.3.1-26-gb76a