Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] How to display one song? #232

Open
eldinor opened this issue Mar 2, 2017 · 3 comments
Open

[Question] How to display one song? #232

eldinor opened this issue Mar 2, 2017 · 3 comments

Comments

@eldinor
Copy link

eldinor commented Mar 2, 2017

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 :)

@bravedave
Copy link

bravedave commented Mar 2, 2017

adjusted index

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';
          }
   }

@eldinor
Copy link
Author

eldinor commented 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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants