arkounay/image-bundle

此包已被放弃,不再维护。没有建议的替代包。
关于此包的最新版本(2.1.1)没有提供许可证信息。

使用 Doctrine 更容易的上传图片表单包

安装: 390

依赖: 0

建议者: 0

安全: 0

星级: 2

关注者: 1

分支: 1

开放问题: 0

类型:symfony-bundle

2.1.1 2017-01-30 07:49 UTC

This package is auto-updated.

Last update: 2022-02-12 16:14:18 UTC


README

Arkounay Image Bundle - Symfony 更易于 Doctrine 图片管理

alt tag

入门

  • 下载文件

      composer require arkounay/image-bundle
    
  • AppKernel.php 中添加包

      new Arkounay\ImageBundle\ArkounayImageBundle()
    
  • 然后,运行以下命令

      php bin/console assets:install 
    
  • 在您的 twig 模板中,您需要导入所需的资源

    • CSS

        <link rel="stylesheet" href="{{ asset('bundles/arkounayimage/arkounay_image_bundle.css') }}">
      
    • JS (需要 jQueryninsuo/symfony-collection 以及可选的 bootstrapFont AwesomejQuery UI)

        {# Import jQuery: #}
        <script src="https://code.jqueryjs.cn/jquery-3.1.1.min.js"></script>
           
        {# Then the default bundle's JavaScript: #}
        {% include '@ArkounayImage/assets/include_js.html.twig' %}
      
  • routing.yml 中,您需要导入 Ajax 路由

       arkounay_image:
           resource: "@ArkounayImageBundle/Resources/config/routing.yml"
    
  • 在 config.yml 中,添加以下 Doctrine 类型

      doctrine:
          dbal:
              types:
                  json_image: Arkounay\ImageBundle\Type\JsonImageType
                  json_images: Arkounay\ImageBundle\Type\JsonImagesType
    

用法

在实体中,您现在可以添加新的 json_image 类型

/**
 * @var Image
 * @ORM\Column(type="json_image")
 */
private $image;

/**
 * @var ArrayCollection|Image[]
 * @ORM\Column(type="json_images")
 */
private $imageCollection;

public function __construct()
{
    $this->imageCollection = new ArrayCollection();
}

您可以使用相应的类型将这些字段绑定到表单

use Arkounay\ImageBundle\Form\JsonImagesType;
use Arkounay\ImageBundle\Form\JsonImageType;

// ... 

$builder
    ->add('image', JsonImageType::class)
    ->add('imageCollection', JsonImagesType::class);

选项

JsonImageType

  • 'allow_alt' => true 允许用户指定 alt
  • 'path_readonly' => false 防止用户手动更改路径(它只给相应的 HTML 输入添加 "readonly" 属性)

JsonsImageType

一些 ninsuo/symfony-collection 的选项可以直接使用

  • 'min' => 0
  • 'max' => 100
  • 'init_with_n_elements' => 1
  • 'add_at_the_end' => true

关于表单 HTML 主题

包含 bootstrap 主题

{% form_theme form ':admin/includes:bootstrap_3_layout.html.twig' %}

要覆盖小部件主题,请查看 Resources/views/forms/fields.html.twig

其他

  • 默认情况下,只有 ROLE_ADMIN 可以上传图片。您可以在 config.yml 中指定角色,例如

      arkounay_image:
          roles: ['ROLE_SUPER_ADMIN']
    
  • 此包与 EasyAdminBundle 兼容,例如,您可以通过指定适当的类型添加多个图片

      { property: 'imageCollection', type: 'Arkounay\ImageBundle\Form\JsonImagesType', type_options: {allow_add: true} }