Trow PageNotFoundException if car, track, user or race don't exists
This commit is contained in:
parent
ca004ee472
commit
01de175fe9
4 changed files with 20 additions and 12 deletions
|
@ -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();
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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]);
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue