webmil / filepickerio-bundle
Symfony WebmilFilepickerIoBundle
dev-master
2013-09-11 16:33 UTC
Requires
- php: >=5.3.2
- symfony/framework-bundle: >=2.1,<2.4
Requires (Dev)
- twig/twig: *
This package is not auto-updated.
Last update: 2024-09-14 12:04:57 UTC
README
安装
步骤 1) 下载包
方法 a) 使用 composer (symfony 2.1 模式)
在 composer.json 中添加以下内容(见 https://getcomposer.org.cn/)
"require" : {
// ...
"webmil/filepickerio-bundle": "dev-master",
}
方法 b) 使用 deps
文件(symfony 2.0 模式)
将以下行添加到您的 deps
文件中,然后运行 php bin/vendors install
[WebmilFilepickerIoBundle]
git=https://github.com/imsashko/WebmilFilepickerIoBundle.git
target=bundles/Webmil/FilepickerIoBundle
version=origin/2.0
步骤 2) 注册命名空间
如果您通过 composer 安装了包,请使用创建的 autoload.php(跳到步骤 3)。将以下命名空间条目添加到您的自动加载器中的 registerNamespaces
调用中
<?php // app/autoload.php $loader->registerNamespaces(array( // ... 'Webmil\\FilepickerIoBundle' => __DIR__.'/../vendor/bundles', // ... ));
步骤 3) 注册包
要开始使用此包,请在您的 Kernel 中注册它
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Webmil\FilepickerIoBundle\WebmilFilepickerIoBundle(), ); // ... }
步骤 4) 配置包
# app/config/config.yml webmil_filepicker_io: api_key: yourKey
用法
在 twig 模板中初始化
{{ filepicker_io_initialize() }}
在您的表单中添加一个上传字段
在表单构建器中将 type 设置为 'filepicker'。要启用拖放,请设置 'dragdrop' => true。有关完整选项列表,请参阅 filepicker.io 文档。
$form = $this->createFormBuilder() ->add('filepicker', 'filepicker', array( 'dragdrop' => true, 'attr' => array( 'data-fp-mimetype' => 'image/png' ) )) ->getForm();
显示图片
{{ filepicker_io_image_tag('https://www.filepicker.io/api/file/hFHUCB3iTxyMzseuWOgG', {'w': '200'}, {'class': 'classname'}) }}
有关完整选项列表,请参阅 filepicker.io 文档。
允许用户下载文件(或将文件上传到任何支持的云服务)
{{ filepicker_io_save_button('http://path/to/file.png', 'Download file', 'image/png', {'data-fp-suggestedFilename': 'name.png'}) }}
有关完整选项列表,请参阅 filepicker.io 文档。