diff --git a/about.php b/controllers/about.php similarity index 70% rename from about.php rename to controllers/about.php index 18bb937..1567258 100644 --- a/about.php +++ b/controllers/about.php @@ -1,4 +1,3 @@ 'controllers/index.php', + '/about' => 'controllers/about.php', + '/contact' => 'controllers/contact.php', + '/mission' => 'controllers/mission.php', +]; + +function routeToController($uri, $routes) { + if (array_key_exists($uri, $routes)) { + require $routes[$uri]; + } else { + abort(); + } +} + +routeToController($uri, $routes); + +function abort($code = 404) { + http_response_code($code); + require "views/{$code}.php"; + die(); +} \ No newline at end of file diff --git a/router.php b/router.php new file mode 100644 index 0000000..9738e59 --- /dev/null +++ b/router.php @@ -0,0 +1,25 @@ + 'controllers/index.php', + '/about' => 'controllers/about.php', + '/contact' => 'controllers/contact.php', + '/mission' => 'controllers/mission.php', +]; + +function routeToController($uri, $routes) { + if (array_key_exists($uri, $routes)) { + require $routes[$uri]; + } else { + abort(); + } +} + +routeToController($uri, $routes); + +function abort($code = 404) { + http_response_code($code); + require "views/{$code}.php"; + die(); +} \ No newline at end of file diff --git a/views/404.php b/views/404.php new file mode 100644 index 0000000..85740ed --- /dev/null +++ b/views/404.php @@ -0,0 +1,12 @@ + + + +
+
+

Sorry. Page Not Found.

+

+ Go back home. +

+
+
+ \ No newline at end of file diff --git a/views/partials/nav.php b/views/partials/nav.php index f2143a8..ca1c323 100644 --- a/views/partials/nav.php +++ b/views/partials/nav.php @@ -10,11 +10,11 @@ Home - About + About - Contact + Contact - Our Mission + Our Mission