diff --git a/app/Controllers/Cars.php b/app/Controllers/Cars.php index 62a33f4..ab61ed5 100644 --- a/app/Controllers/Cars.php +++ b/app/Controllers/Cars.php @@ -16,6 +16,9 @@ class Cars extends BaseController { $this->cachePage(3600); $car = $this->carsModel->data($id); + + if (!$car) throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound(); + echo get_header('Car: ' . $car->name); echo view('car', ['car' => $car]); echo get_footer(); diff --git a/app/Controllers/Races.php b/app/Controllers/Races.php index f4d5214..d3df115 100644 --- a/app/Controllers/Races.php +++ b/app/Controllers/Races.php @@ -31,19 +31,18 @@ class Races extends BaseController $tplData = []; - if ($query && $query->getNumRows() == 1) - { - $tplData['race'] = $query->getRow(); - $builder = $this->db->table('laps'); - $builder->where('race_id', $tplData['race']->id); - $query = $builder->get(); + if (!$query || $query->getNumRows() == 0) throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound(); + + $tplData['race'] = $query->getRow(); + $builder = $this->db->table('laps'); + $builder->where('race_id', $tplData['race']->id); + $query = $builder->get(); - $tplData['race']->n_laps = 0; - if ($query && $query->getNumRows() > 0) - { - $tplData['laps'] = json_encode($query->getResult()); - $tplData['race']->n_laps = $query->getNumRows(); - } + $tplData['race']->n_laps = 0; + if ($query && $query->getNumRows() > 0) + { + $tplData['laps'] = json_encode($query->getResult()); + $tplData['race']->n_laps = $query->getNumRows(); } echo get_header('Races'); diff --git a/app/Controllers/Tracks.php b/app/Controllers/Tracks.php index a8a542d..5c6e940 100644 --- a/app/Controllers/Tracks.php +++ b/app/Controllers/Tracks.php @@ -16,6 +16,9 @@ class Tracks extends BaseController { $this->cachePage(3600); $track = $this->tracksModel->data($id); + + if (!$track) throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound(); + $bestLaps = getBestTimesTrack($id); echo get_header('Track: ' . $track->name); echo view('track', ['track' => $track, 'bestLaps' => $bestLaps]); diff --git a/app/Controllers/Users.php b/app/Controllers/Users.php index 703a58e..78bfc36 100644 --- a/app/Controllers/Users.php +++ b/app/Controllers/Users.php @@ -26,6 +26,9 @@ class Users extends BaseController { //$this->cachePage(3600); $user = $this->usersModel->getUser($username); + + if (!$user) throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound(); + $userraces = $this->usersModel->getRaces(); $raceswon = $this->usersModel->getWon(); $racespodiums = $this->usersModel->getPodiums();