Skip to content

[Question] How to display one song? #232

Open

Description

@eldinor

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

Activity

  1. bravedave commented on Mar 2, 2017

    @bravedave

    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';
              }
       }
    
  2. eldinor commented on Mar 3, 2017

    @eldinor
    Author

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

  3. bravedave commented on Mar 3, 2017

    @bravedave

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions