if (isset($routes[$this->route]['login']) &&
isset($routes[$this->route]['login']) &&
!$authentication->isLoggedIn()) {
header('location: /login/error');
}
1. You are checking the exact same thing twice (isset($routes[$this->route]['login'])).
2. The $authentication variable is not defined in the text. The following is missing above the if statement:
$authentication = $this->routes->getAuthentication();
The code example should instead look like this:
public function run()
{
$routes = $this->routes->getRoutes();
$authentication = $this->routes->getAuthentication();
if (isset($routes[$this->route]['login']) && !$authentication->isLoggedIn()) {
header('location: /login/error');
} else {
$controller = $routes[$this->route][$this->method]['controller'];
$action = $routes[$this->route][$this->method]['action'];
$page = $controller->$action();
$title = $page['title'];
if (isset($page['variables'])) {
$output = $this->loadTemplate($page['template'], $page['variables']);
} else {
$output = $this->loadTemplate($page['template']);
}
include __DIR__ . '/../../templates/layout.html.php';
}
}
Link to content: PHP & MySQL: Novice to Ninja, 6th Edition - Section 11