general fixes

This commit is contained in:
Joshua Perry 2023-01-23 17:50:22 +00:00
parent 05ee8bbeb8
commit 09a0367bdc
4 changed files with 40 additions and 6 deletions

View File

@ -20,8 +20,13 @@ class EntryPoint {
$route = $this->routes->getDefaultRoute(); $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 == '') { if ($functionName == '') {
$functionName = 'home'; $functionName = 'home';
} }
@ -30,7 +35,13 @@ class EntryPoint {
$functionName = $functionName . 'Submit'; $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']); $content = $this->loadTemplate('../templates/' . $page['template'], $page['vars']);
$nav = $this->loadTemplate('../templates/nav.html.php', $page['vars']); $nav = $this->loadTemplate('../templates/nav.html.php', $page['vars']);
$title = $page['title']; $title = $page['title'];

View File

@ -8,9 +8,15 @@ class Routes implements \CSY2028\Routes {
$controllers = []; $controllers = [];
//TODO: Add 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() { 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()]
];
}
} }

View File

@ -1,4 +1,5 @@
<?php <?php
session_start();
require '../autoload.php'; require '../autoload.php';
$routes = new \jobs\Routes(); $routes = new \jobs\Routes();
$entryPoint = new \CSY2028\EntryPoint($routes); $entryPoint = new \CSY2028\EntryPoint($routes);

View File

@ -5,7 +5,7 @@
<h2><?=$job->title?></h2> <h2><?=$job->title?></h2>
<h3><?=$job->salary?></h2> <h3><?=$job->salary?></h2>
<p><?=nl2br($job->description)?></p> <p><?=nl2br($job->description)?></p>
<a class="more" href="/apply.php">Apply for this job</a> <a class="more" href="/jobs/apply?id=<?=$job->id?>">Apply for this job</a>
</div> </div>
</li> </li>
<?php } ?> <?php } ?>