Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions application/Controller/SongsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,16 @@ public function editSong($song_id)
// do getSong() in model/model.php
$song = $Song->getSong($song_id);

// in a real application we would also check if this db entry exists and therefore show the result or
// redirect the user to an error page or similar

// load views. within the views we can echo out $song easily
require APP . 'view/_templates/header.php';
require APP . 'view/songs/edit.php';
require APP . 'view/_templates/footer.php';
// If the song wasn't found, then it would have returned false, and we need to display the error page
if ($song === false) {
$page = new \Mini\Controller\ErrorController();
$page->index();
} else {
// load views. within the views we can echo out $song easily
require APP . 'view/_templates/header.php';
require APP . 'view/songs/edit.php';
require APP . 'view/_templates/footer.php';
}
} else {
// redirect user to songs index page (as we don't have a song_id)
header('location: ' . URL . 'songs/index');
Expand Down
2 changes: 1 addition & 1 deletion application/Model/Song.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function getSong($song_id)
$query->execute($parameters);

// fetch() is the PDO method that get exactly one result
return $query->fetch();
return ($query->rowcount() ? $query->fetch() : false);
}

/**
Expand Down