drmonkeyninja / cakephp-tmdb
CakePHP TMDB API integration
Installs: 44
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 4
Forks: 1
Open Issues: 1
Type:cakephp-plugin
Requires
- cakephp/cakephp: ~3.0
- muffin/webservice: ^1.3
- php-tmdb/api: ^2.1
This package is auto-updated.
Last update: 2024-11-07 16:06:35 UTC
README
This CakePHP 3 plugin provides integration with the TMDB API for retrieving data on movies and television from themoviedb.org. It makes use of an established TMDB API wrapper and the Webservice plugin for CakePHP.
Requirements
- CakePHP 3.x
- A valid TMDB API key
Installation
Install using composer: composer require drmonkeyninja/cakephp-tmdb:3.0.*
Then add the following lines to bootstrap.php to load the plugin:
Plugin::load('Muffin/Webservice'); Plugin::load('CakeTmdb');
Configuration
You will need to configure a new webservice in config/app.php using your TMDB API key:
'Webservices' => [ 'Tmdb' => [ 'className' => 'Muffin\Webservice\Connection', 'service' => 'CakeTmdb\Lib\Tmdb\Driver\Tmdb', 'api_key' => 'your_tmdb_api_key' ] ]
Then in bootstrap.php instruct the ConnectionManager
to consume the webservice:
ConnectionManager::setConfig(Configure::consume('Webservices'));
Usage
This plugin uses the TMDB API library so you have full access to all of the methods provided there.
For example, to search the database for movies with the title 'Toy Story':
$tmdb = \Cake\Datasource\ConnectionManager::get('Tmdb'); $data = $tmdb->getSearchApi()->searchMovies('Toy Story');
TmdbHelper
A handy little helper comes with the plugin for rendering TMDB images using the paths returned by the API. To use include the Tmdb
helper in your controller as normal:-
public $helpers = ['CakeTmdb.Tmdb'];
Then in your view:-
<?= $this->Tmdb->image($movie->poster, 'w154'); ?>
The first parameter needs to be the image path (provided by TMDB); the second parameter is the TMDB size. You can also pass an optional array of image attributes as the third parameter:-
<?= $this->Tmdb->image($movie->poster, 'w154', ['alt' => $movie->title]); ?>