List of film genres
Closed this issue · 11 comments
I looked a little at the codes and I tried the one you offer
foreach($movie->getGenres() as $genre){ echo $genre->getName(); }
But I have an error that I cannot resolve
Notice: Trying to access array offset on value of type int in C:\wamp64\www\tmdb_v3-PHP-API--master\controller\classes\data\Genre.php on line 49
Can you help me I just have that to finish my script, thank you in advance
Hello @HellsAngels
where is the code provided you mentioned in the beginning? can't find it in the examples of this repository.
Nevertheless your code example and your error message are somehow not related.
In your code you iterate over the genres of a movie (when they exist) and print the name of the genre.
But your error message is for getting the Id of a Genre.
Maybe you can provide further details on what you are doing, how you are doing it and what you want to achieve?
the error reports this code to me Genre.php line 49
return $this->_data['id'];
What I want to do is display the Genres. But in Movie.php this $this->_data['genres'] code gives me this error!
Undefined index: genres in C:\wamp64\www\tmdb_v3-PHP-API--master\controller\classes\data\Movie.php on line 106
And if I put this $ this->_data['genre_ids'] it is this error
Trying to access array offset on value of type int in C:\wamp64\www\tmdb_v3-PHP-API--master\controller\classes\data\Genre.php on line 49
And I call the genre like this
foreach($movie->getGenres() as $genre){
echo ''. $genre->getName() .'';
}
I do not know what to do. Yet your code works well except genres
Is it the Detail of a Movie or for example a search result of a movie? Are you iterating over a movie list?
From which endpoint do you get your movie / movies?
For example when you first search for a movie by keyword and receive a movie list and then want to display the genres of each movie (search result) then you only have the genre ids.
Will look into this Genre thing and hopefully provide an example.
It’s while searching for a movie, so it’s just the genre IDs that it displays ,? If so, what would be nice is that with genre IDs we can have a list of genres.
You were talking about it here (#40) and it is on this discussion that I tried to display the genres, but I had not seen that it was just on the info of a film and not the research
@HellsAngels
You can have a look into the official API Docs.
Movie Details:
https://developers.themoviedb.org/3/movies/get-movie-details
Movies in Search Results:
https://developers.themoviedb.org/3/search/search-movies
Look into the Responses. There you will see that on the Details Endpoint you receive the Genres Array on the Search Endpoint only an Array of Genre Ids.
That means when you want to display each Genre Name for a Movie search result you have to iterate over the ids and fetch the genre details. Unfortunately there is currently no function for fetching Genre Details by Id.
@HellsAngels
I added some examples for genres in my latest commit on my fork check them out:
https://github.com/bogdanfinn/tmdb_v3-PHP-API-
That means when you want to display each Genre Name for a Movie search result you have to iterate over the ids and fetch the genre details. Unfortunately there is currently no function for fetching Genre Details by Id.
But fetchig the genre details is only one API call. See the examples. then you receive a list of genres and you only need to filter the genres you are intereted in. You dont have to do an api call for each genre
Ok thank you I will go see the details of the API. And sorry for the inconvenience because actually during the search we only have the gender IDs.
@bogdanfinn Can you do a pull request?
@pixelead0 created one for all 3 open issues
@pixelead0 issue can be closed
thanks @bogdanfinn