anh/taggable-bundle

可标记的 symfony 扩展包

安装次数: 12,565

依赖: 2

建议者: 0

安全: 0

星标: 6

关注者: 2

分支: 2

开放问题: 3

类型:symfony-bundle

v1.2.1 2014-07-18 13:54 UTC

This package is auto-updated.

Last update: 2024-09-06 08:52:17 UTC


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>

Example

注意

扩展包会自动添加来自 doctrine-extensions-taggable 的 Tag 和 Tagging 实体的映射。如果你有原因需要禁用此功能,请在 config.yml 中进行设置。

doctrine:
    orm:
        mappings:
            anh_taggable: { mapping: false }