pixelead0 / tmdb_v3-PHP-API-

Wrapper in PHP for The Movie Data Base version 3
119 stars 82 forks source link

List movie genres in link #40

Closed orig921 closed 6 years ago

orig921 commented 8 years ago

Hi! I tried: "echo $movie->getGenres()" and a got: "Array". How can I list genres of a link as a link? I want to list genres names as a link. The link href is the genre id.

bogdanfinn commented 7 years ago

The $movie->getGenres() function returns an array of Genre Objects or null.

You have to iterate over the array and build the link yourself. For example: foreach($movie->getGenres() as $genre){ echo '<a href="https://www.themoviedb.org/genre/'.$genre->getId().'">'. $genre->getName() .'</a>'; }

As far as i know you only get the Genres when you request Information for a specific movie. When you try to call $movie->getGenres() on a $movie object in a search result list for example the property genres does not exist.

Hope i could help you :)