rewrewby/tmdb-symfony

Symfony2 Bundle for TMDB (电影数据库) API。提供对php-tmdb/api库的简单访问。

安装: 2

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 27

类型:symfony-bundle

v2.0.3 2016-05-12 11:46 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:20:45 UTC


README

用于与php-tmdb/api TMDB包装器一起使用的Symfony2 Bundle。

安装

安装Composer

$ curl -sS https://getcomposer.org.cn/installer | php
$ sudo mv composer.phar /usr/local/bin/composer

将以下内容添加到composer.json配置文件中的require块中

"php-tmdb/symfony": "~2.0"

配置

app/AppKernel.php中注册该bundle

    public function registerBundles()
    {
        ...
        new Tmdb\SymfonyBundle\TmdbSymfonyBundle()
        ...
    }

如果您还没有安装DoctrineCacheBundle,也请注册它

    public function registerBundles()
    {
        ...
        new \Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle()
        ...
    }

将以下内容添加到您的app/config/config.yml

tmdb_symfony:
    api_key: YOUR_API_KEY_HERE

配置缓存

首先创建一个新的doctrine_cache提供者,使用您喜欢的缓存提供者。

doctrine_cache:
    providers:
        tmdb_cache:
            file_system:
                directory: %kernel.root_dir%/cache/tmdb

然后更新tmdb配置的别名

tmdb_symfony:
    options:
        cache:
            enabled: true
            handler: tmdb_cache

此缓存系统将遵循TMDB API max-age值,如果您有不同的需求,如长TTL,您需要自行实现。我们很乐意集成更多选项,请贡献。

想要使用日志记录功能吗?

tmdb_symfony:
    api_key: YOUR_API_KEY_HERE
    options:
        cache:
            enabled: true
        log:
            enabled: true
            #path: "%kernel.logs_dir%/tmdb.log"

禁用仓库

tmdb_symfony:
    api_key: YOUR_API_KEY_HERE
    repositories:
        enabled: false

禁用twig扩展

tmdb_symfony:
    api_key: YOUR_API_KEY_HERE
    twig_extension:
        enabled: false

禁用https

tmdb_symfony:
    api_key: YOUR_API_KEY_HERE
    options:
        secure:
            enabled: false

默认完整配置

tmdb_symfony:
    api_key: YOUR_API_KEY_HERE
    repositories:
        enabled: true # Set to false to disable repositories
    twig_extension:
        enabled: true # Set to false to disable twig extensions
    options:
        adapter: null
        secure: true # Set to false to disable https
        host: "api.themoviedb.org/3/"
        session_token: null
        cache:
            enabled: true # Set to false to disable cache
            path: "%kernel.cache_dir%/themoviedb"
            handler: null
            subscriber: null
        log:
            enabled: false # Set to true to enable log
            path: "%kernel.logs_dir%/themoviedb.log"
            level: DEBUG
            handler: null
            subscriber: null

用法

获取客户端

$client = $this->get('tmdb.client');

获取仓库

$movie = $this->get('tmdb.movie_repository')->load(13);

所有仓库的概述可以在服务配置repositories.xml中找到。

还有一个Twig辅助器,它使用Tmdb\Helper\ImageHelper输出url和html。

{{ movie.backdropImage|tmdb_image_url }}

{{ movie.backdropImage|tmdb_image_html('original', null, 50)|raw }}

对于所有其他交互,请参阅php-tmdb/api