承接 tiloweb/base64-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tiloweb/base64-bundle

最新稳定版本:1.2.4

Composer 安装命令:

composer require tiloweb/base64-bundle

包简介

/

README 文档

README

This Bundle allow you to manage entities files send through your forms in base64.

Installation

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require tiloweb/base64-bundle "dev-master"

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the Bundle (only for Symfony 2 or 3)

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new Tiloweb\Base64Bundle\TilowebBase64Bundle(),
        );

        // ...
    }

    // ...
}

Step 3: Add the default twig theme

Add the default twig theme for the form in you app/config/config.yml for Symfony 2 and 3 app/config/packages/twig.yml for Symfony 4.

# app/config/config.yml

twig:
    form_themes:
        - '@TilowebBase64/form/fields.html.twig'

Step 4 : Configure your form type

<?php
// src/AppBundle/Form/ImageType.php

use App\Entity;
use Tiloweb\Base64Bundle\Form\Base64Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class ImageType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add("avatar", Base64Type::class, array(
                'label' => 'Avatar',
                'required' => false, // Can be true
                'deleteLabel' => 'Delete', // Optional if "required" is true, default : "Delete"
                'width' => 600, // Optionnal : If set, the image will be resized
                'height' => 400 // Optionnal : If not setted, the ratio will be respected, if setted with width, the image will be cropped.
            ))
        ;
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => Avatar::class,
        ));
    }
}

Step 5 : Enjoy !

Now, your form will show an file input. When you select an image, the preview is updated. If the field is not required, a "delete" button is shown. When the form is submited, you'll receive the base64 url of the image.

统计信息

  • 总下载量: 12.97k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 2
  • Forks: 0
  • 开发语言: HTML

其他信息

  • 授权协议: GNU
  • 更新时间: 2016-07-26