diff --git a/CSY2028/EntryPoint.php b/CSY2028/EntryPoint.php index 98e570b..581441f 100644 --- a/CSY2028/EntryPoint.php +++ b/CSY2028/EntryPoint.php @@ -20,8 +20,13 @@ class EntryPoint { $route = $this->routes->getDefaultRoute(); } - list($controllerName, $functionName) = \explode('/', $route); - + if (count(\explode('/', $route)) == 1) { + $controllerName = \explode('/', $route)[0]; + $functionName = ""; + } + else { + list($controllerName, $functionName) = \explode('/', $route); + } if ($functionName == '') { $functionName = 'home'; } @@ -30,7 +35,13 @@ class EntryPoint { $functionName = $functionName . 'Submit'; } - $page = $this->routes->getController($controllerName)->$functionName(); + $page = $this->routes->getController($controllerName); + if ($page == null) { + $page = $this->routes->notFound(); + } + else { + $page = $page->$functionName(); + } $content = $this->loadTemplate('../templates/' . $page['template'], $page['vars']); $nav = $this->loadTemplate('../templates/nav.html.php', $page['vars']); $title = $page['title']; diff --git a/jobs/Routes.php b/jobs/Routes.php index a69113f..d4039f0 100644 --- a/jobs/Routes.php +++ b/jobs/Routes.php @@ -8,9 +8,15 @@ class Routes implements \CSY2028\Routes { $controllers = []; //TODO: Add Controllers - $controllers['jobs'] = new \jobs\controllers\Jobs($jobsTable, $catsTable); + $controllers['jobs'] = new \jobs\controllers\Jobs($jobsTable, $catsTable, $appsTable); + + if (array_key_exists($name, $controllers)) { + return $controllers[$name]; + } + else { + return null; + } - return $controllers[$name]; } public function getDefaultRoute() { @@ -30,4 +36,20 @@ class Routes implements \CSY2028\Routes { } } + + public function notFound() { + $cats = new \CSY2028\DatabaseTable('category', 'id', '\jobs\Entity\Category'); + return ['template' => 'response.html.php', + 'title' => 'Jo\'s Jobs- 404 Not Found', + 'vars' => ['cats' => $cats->findAll(), + 'response' => '404 Page Not Found'] + ]; + } + + public function nav() { + $cats = new \CSY2028\DatabaseTable('category', 'id', '\jobs\Entity\Category'); + return ['template' => 'nav.html.php', + 'vars' => ['cats' => $cats->findAll()] + ]; + } } \ No newline at end of file diff --git a/public/index.php b/public/index.php index 1603ce2..7ad167b 100644 --- a/public/index.php +++ b/public/index.php @@ -1,4 +1,5 @@ =$job->title?>
=nl2br($job->description)?>
- Apply for this job + Apply for this job