You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, great thanks for this project - it helps a lot to know about MVC for such beginners as I am.
Maybe this question is too simple, but my current knowledge of PHP doesn't let to solve it by myself.
So, if you call http://example.com/mini/songs/ the script calls the index method of the songs controller.
What should I do to get the page like http://example.com/mini/songs/1 (where song with id=1 will be displayed)?
I suppose that in this case I need another method in the songs controller. But how to pass the id to this method? Probably it should be done in core/application.php?
I will be very grateful for the answers. Pieces of code are welcome :)
public function index( $songID = 0)
{
if ( ( $songID = (int)$songID) > 0) {
// then $songID must not be zero
// so tell them all about song number one - something like
$song = $this->model->getSong( $songID);
// load views. within the views we can echo out $songs and $amount_of_songs easily
require APP . 'view/_templates/header.php';
require APP . 'view/songs/songview.php';
require APP . 'view/_templates/footer.php';
}
else {
// getting all songs and amount of songs
$songs = $this->model->getAllSongs();
$amount_of_songs = $this->model->getAmountOfSongs();
// load views. within the views we can echo out $songs and $amount_of_songs easily
require APP . 'view/_templates/header.php';
require APP . 'view/songs/index.php';
require APP . 'view/_templates/footer.php';
}
}
Thanks a lot!
But everything what I've got is the Problem page...
Seems that song ID is detected as action but doesn't have proper method.
Below there is data from debug mode.
Activity
bravedave commentedon Mar 2, 2017
adjusted index
eldinor commentedon Mar 3, 2017
Thanks a lot!
But everything what I've got is the Problem page...
Seems that song ID is detected as action but doesn't have proper method.
Below there is data from debug mode.
http://localhost/mini/songs/deletesong/3
Controller: songs
Action: deletesong
Parameters: Array ( [0] => 3 )
http://localhost/mini/songs/4
Controller: songs
Action: 4
Parameters: Array ( )
bravedave commentedon Mar 3, 2017
I think your right there - you have to go to a function - so like the deletesong example
i.e. http://localhost/mini/songs/viewsong/3