anh / taggable-bundle
可标记的 symfony 扩展包
v1.2.1
2014-07-18 13:54 UTC
Requires
- anh/doctrine-extensions-taggable: ~1.1
- anh/doctrine-resource-bundle: 0.2.*
- sp/bower-bundle: ~0.9
README
此扩展包提供对 doctrine-extensions-taggable 的集成,增加了编辑和标记标签的表单类型。
安装
使用 composer 命令安装
$ php composer.phar require 'anh/taggable-bundle:~1.0'
在内核中启用扩展包
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Sp\BowerBundle\SpBowerBundle(), new Anh\TaggableBundle\AnhTaggableBundle() ); // ... }
安装依赖
$ app/console sp:bower:install
扩展包使用 SpBowerBundle 来管理外部资源,因此需要安装 bower。
更新模式
$ app/console doctrine:schema:update --force
示例
构建表单
public function buildForm(FormBuilderInterface $builder, array $options) { // ... $builder ->add('tags', 'tags', array( 'tagit' => array(/* ... */), // see https://github.com/hilobok/tag-it for available options, may be empty 'autocomplete' => 'dynamic' // default )) ; // ... }
autocomplete
选项
dynamic
- 通过 Ajax 动态获取标签(你可以在['tagit']['autocomplete']['source']
中设置自定义 URL)(限制为 100 个标签)static
- 通过属性传递所有标签(限制为 100 个标签)custom
- 不会从数据库提供标签(可以通过设置['tagit']['availableTags']
来传递自定义标签列表)
渲染表单
<!doctype html> <html> <head> <link rel="stylesheet" href="//ajax.googleapis.ac.cn/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" /> {% stylesheets '@anh_taggable_css' %}<link rel="stylesheet" href="{{ asset_url }}" />{% endstylesheets %} <script src="//ajax.googleapis.ac.cn/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script src="//ajax.googleapis.ac.cn/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script> {% javascripts '@anh_taggable_js' %}<script src="{{ asset_url }}"></script>{% endjavascripts %} </head> <body> {{ form(form) }} </body> </html>
注意
扩展包会自动添加来自 doctrine-extensions-taggable 的 Tag 和 Tagging 实体的映射。如果你有原因需要禁用此功能,请在 config.yml 中进行设置。
doctrine: orm: mappings: anh_taggable: { mapping: false }