xiранst / media-bundle
帮助您的应用程序更轻松地上传文件。
dev-master / 1.x-dev
2017-04-12 15:11 UTC
Requires
- php: >=5.4.0
- symfony/symfony: >=3.0
This package is not auto-updated.
Last update: 2024-09-20 19:30:05 UTC
README
帮助您的应用程序更轻松地上传文件。
1, 使用composer安装
$ composer require xiranst/media-bundle:dev-master
2, 在AppKernel.php中启用
// app/AppKernel.php <?php // ... public function registerBundles() { $bundles = array( // ... new Xiranst\Bundle\MediaBundle\XiranstMediaBundle(), ); }
3, 在表单类型中使用
<?php // src/Xiranst/Bundle/DemoBundle/Form/YourFormType.php namespace Xiranst\Bundle\DemoBundle\Form; use Xiranst\Bundle\MediaBundle\Form\ThumbnailType; class YourFormType extends AbstractType { /** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { // ... $builder->add('thumbnail', ThumbnailType::class); // ... } // ... }
4, 选项
a, 在config.yml中配置上传目录
默认目录是
%kernel.root_dir%/../web/uploads/media
请确保web/uploads/media目录的权限为0777;
如果您需要更改此路径,请将此配置添加到config.yml中
// app/config/config.yml xiranst_media: upload_directory: '%kernel.root_dir%/../your-directory/'
b, 如果文件已上传并且您想在表单模板中显示它,可以使用以下代码
{{ form.vars.data.thumbnail }}