l3 / photo-bundle
RefPhoto Symfony2/Symfony3/Symfony4/Symfony5/Symfony6/Symfony7 的 PhotoBundle 客户端
1.0.7
2024-07-30 09:10 UTC
Requires
- php: >=8.2
- symfony/framework-bundle: ~7.0
- twig/twig: ~2.0 || ~3.0
README
此包是参考 Photo (https://github.com/l3-team/RefPhoto) 或 (https://github.com/l3-team/RefPhotoJ2EE) 的客户端
先决条件
- 已安装 RefPhoto 实例 (https://github.com/l3-team/RefPhoto) 或 (https://github.com/l3-team/RefPhotoJ2EE)
- 拥有一个 Symfony 2 或 Symfony3 或 Symfony4 应用程序
安装
使用以下命令安装 Bundle
composer require l3/photo-bundle:~1.0
对于 Symfony 2 和 Symfony3,在 AppKernel.php 中添加 Bundle
<?php
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new L3\Bundle\PhotoBundle\L3PhotoBundle(),
);
// ...
}
// ...
}
对于 Symfony4,在 config/bundles.php 文件中添加 bundle(如果不存在则添加行)
<?php
// config/bundles.php
return [
...
L3\Bundle\PhotoBundle\L3PhotoBundle::class => ['all' => true],
...
];
配置
对于 Symfony2 和 Symfony3,在 app/config/parameters.yml.dist 和 app/config/parameters.yml 中添加并适应配置的 3 个变量
# app/config/parameters.yml.dist
# app/config/parameters.yml
parameters:
photo_enabled: true
photo_image_url: 'https://refphotos.univ.fr/image/'
photo_token_url: 'https://refphotos.univ.fr/token/add'
接下来,在 app/config/config.yml 下的 twig globals 中添加变量 %photo_enabled%
# app/config/config.yml
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
globals:
photo_enabled: '%photo_enabled%'
对于 Symfony4,在 .env.local 和 .env 中添加并适应配置的 3 个变量
# .env.local
# .env
###> l3/photo-bundle ###
PHOTO_ENABLED=true
PHOTO_IMAGE_URL=https://refphotos.univ.fr/image/
PHOTO_TOKEN_URL=https://refphotos.univ.fr/token/add/
###< l3/photo-bundle ###
并在 config/services.yaml 文件中的 parameters 下添加 3 个变量
# config/services.yaml
parameters:
photo_enabled: '%env(bool:PHOTO_ENABLED)%'
photo_image_url: '%env(string:PHOTO_IMAGE_URL)%'
photo_token_url: '%env(string:PHOTO_TOKEN_URL)%'
并在 config/packages/twig.yaml 下的 twig globals 中添加变量 %photo_enabled%
# config/packages/twig.yaml
# Twig Configuration
twig:
paths: ['%kernel.project_dir%/templates']
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'
globals:
photo_enabled: '%photo_enabled%'
如何使用
在你的 twig 视图中,你可以这样使用它
{% if photo_enabled %}
<img src="{{ photo(p.uid) }}" alt="photo inexistante" />
{% endif %}