diff options
Made index.php a router and added the basis of landing view and controller
4 files changed, 34 insertions, 9 deletions
| -rw-r--r-- | src/controllers/LandingController.php | 9 | ||||
| -rw-r--r-- | src/index.php | 26 | ||||
| -rw-r--r-- | src/models/DB.php | 1 | ||||
| -rw-r--r-- | src/views/landing.php | 7 |
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 @@ +<?php +include_once("models/JobOffer.php"); + +class LandingController { + function invoke() { + $jobs = JobOffer::getAllFromDB(); + include "views/landing.php"; + } +} diff --git a/src/index.php b/src/index.php index 7313cbb..26089e9 100644 --- a/src/index.php +++ b/src/index.php @@ -1,15 +1,25 @@ <?php require "document-top.php"; ?> -<p>Hello World!</p> <?php - include_once("models/JobOffer.php"); +include_once("controllers/LandingController.php"); - $jb = new JobOffer("Test", "A test", "TheTest", 11); - // JobOffer::insertInDB($jb); - foreach(JobOffer::getAllFromDB() as $key => $obj) { - echo "{$obj->id} {$obj->title}<br>"; - } - echo "<br>"; +/* 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; +} ?> <?php require "document-bot.php"; ?> 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 @@ +<p>Landing page!</p> + +<?php + foreach($jobs as $job) { + echo "{$job->id} {$job->title}<br>"; + } +?> |
