diff options
Implemented base controller
3 files changed, 40 insertions, 5 deletions
| -rw-r--r-- | src/controllers/BaseController.php | 27 | ||||
| -rw-r--r-- | src/controllers/LandingController.php | 14 | ||||
| -rw-r--r-- | src/index.php | 4 |
diff --git a/src/controllers/BaseController.php b/src/controllers/BaseController.php new file mode 100644 index 0000000..fd4bedd --- /dev/null +++ b/src/controllers/BaseController.php @@ -0,0 +1,27 @@ +<?php +abstract class BaseController { + public static function invoke() { + switch ($_SERVER["REQUEST_METHOD"]) { + case "POST": + static::post(); + break; + case "PUT": + static::put(); + break; + case "DELETE": + static::delete(); + break; + default: + static::get(); + break; + } + } + + abstract protected static function get(); + + abstract protected static function post(); + + abstract protected static function put(); + + abstract protected static function delete(); +} diff --git a/src/controllers/LandingController.php b/src/controllers/LandingController.php index 80e0b5b..9062918 100644 --- a/src/controllers/LandingController.php +++ b/src/controllers/LandingController.php @@ -1,9 +1,19 @@ <?php include_once("models/JobOffer.php"); +include_once("controllers/BaseController.php"); -class LandingController { - function invoke() { +class LandingController extends BaseController { + public static function get() { $jobs = JobOffer::getAllFromDB(); include "views/landing.php"; } + + protected static function post() { + } + + protected static function put() { + } + + protected static function delete() { + } } diff --git a/src/index.php b/src/index.php index 26089e9..70da9a1 100644 --- a/src/index.php +++ b/src/index.php @@ -7,14 +7,12 @@ include_once("controllers/LandingController.php"); * Thanks https://www.taniarascia.com/the-simplest-php-router/ */ -$landingController = new LandingController(); - $request = $_SERVER['REQUEST_URI']; switch ($request) { case "": case "/": - $landingController->invoke(); + LandingController::invoke(); break; default: http_response_code(404); |
