zmc / image-bundle
Symfony2 插件,用于文件上传和图片处理
dev-master / 1.0.x-dev
2016-04-16 12:20 UTC
Requires
- liip/imagine-bundle: ~1.4
- symfony/framework-bundle: ~2.3|~3.0
This package is not auto-updated.
Last update: 2024-09-18 18:58:56 UTC
README
基本
安装
步骤 1) 获取插件
只需使用 composer 安装插件
composer require zmc/image-bundle:dev-master
步骤 2) 注册新插件
在 AppKernel 中添加新行
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Liip\ImagineBundle\LiipImagineBundle(), new Zmc\ImageBundle\ZmcImageBundle(), ); // ... }
步骤 3) 导入路由
# app/config/routing.yml # some routes can go here... zmc_image: resource: "@ZmcImageBundle/Resources/config/routing.xml" prefix: /zmc-image # ... and some can go here. It's doesen't matter
步骤 4) 配置 LiipImagineBundle。
使用
首先,你需要创建 FormType 类,并仅使用我们的表单类型作为字段
<?php // src/Acme/DemoBundle/Form/Type/DemoType.php // ... /** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('image', 'file_upload_hidden', array( /* required parameters */ 'save_path' => '/../web/uploads', 'web_path' => '/uploads', /* optional parameters */ 'imagine_filter' => 'thumb', // filter name configured for LiipImagineBundle /* acceptable files to upload. Patterns and acceptable parameters you can see there https://w3schools.org.cn/tags/att_input_accept.asp */ 'accept_file_type' => 'image/*', // here provided default value, you can pass any service name which implements /* \Zmc\ImageBundle\Form\Handler\HandlerInterface */ 'handler' => 'zmc_image.form.handler.upload', )) ; } // ...