fullpipe/image-bundle

此包已被弃用且不再维护。未建议替代包。

简单的图片存储

安装: 354

依赖者: 1

建议者: 0

安全: 0

星标: 0

关注者: 0

分支: 0

开放问题: 0

类型:symfony-bundle

v0.0.1 2015-02-16 08:57 UTC

This package is not auto-updated.

Last update: 2020-01-22 17:54:51 UTC


README

简单的图片存储。

安装

添加到你的 composer.json

{
   "require": {
        "fullpipe/image-bundle": "dev-master"
    }
}

并到 AppKernel.php

// app/AppKernel.php
class AppKernel extends Kernel
{
    //...
    public function registerBundles()
    {
        $bundles = array(
            //...
            new Fullpipe\ImageBundle\FullpipeImageBundle()
        );

        return $bundles;
    }
    //...
}

配置

fullpipe_image:
    web_root: /media/image //Web directory
    data_root: %kernel.root_dir%/../web/media/image //Directory for storing images

使用

首先你需要通过你自己的实体扩展 Fullpipe\ImageBundle\Entity\Image。例如我们有一个 Acme\BannerBundle\Entity\Banner

//Acme/BannerBundle/Resources/config/doctrine/Banner.orm.yml

Fullpipe\BannerBundle\Entity\Banner:
    type: entity
    table: acme_banner
    lifecycleCallbacks: {  }

和我们的实体

//Acme/BannerBundle/Entity/Banner.php

namespace Acme\BannerBundle\Entity;

use Fullpipe\ImageBundle\Entity\Image;

/**
 * Banner
 */
class Banner extends Image
{

}

之后我们需要更新 BannerType.php

//Acme/BannerBundle/Form/Type/BannerType.php

namespace Acme\BannerBundle\Form\Type;

use Fullpipe\ImageBundle\Form\Type\ImageType;
use Symfony\Component\Form\FormBuilderInterface;

/**
 * Banner type.
 */
class BannerType extends ImageType
{
    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        //...

        parent::buildForm($builder, $options);

        //..
    }
}

这就完成了

Twig

要获取原始图片的web路径,使用 web_path twig 过滤器。 <img src="{{ banner|web_path }}" /> -> /media/image/some_path.png

LiipImagineBundle

不要忘记使用相同的 data_root 目录

...
liip_imagine:
...
    loaders:
        default:
            filesystem:
                data_root: %kernel.root_dir%/../web/media/image
...

待办事项

  • 测试
  • 模型抽象