coosos / tag-bundle
Symfony TagBundle
1.0.5
2018-03-05 21:55 UTC
Requires
- php: >=7.0
- doctrine/doctrine-bundle: ^1.6
- doctrine/orm: ^2.5
- sensio/framework-extra-bundle: >=3.0
- symfony/form: ^3.0
- symfony/framework-bundle: ^3.0
- twig/extensions: ^1.5
Requires (Dev)
- phpunit/phpunit: ^6.2
README
TagBundle 是基于 Grafikart 视频教程 创建的扩展包。
要求
- Symfony 3.0 及以上版本
- PHP 7.0 及以上版本
- jQuery tagEditor(可选)
- jQuery UI Autocomplete(可选)
安装
步骤 1:下载扩展包
打开命令行,进入项目目录,执行以下命令以下载此扩展包的最新稳定版本
$ composer require coosos/tag-bundle
如果您的系统中已安装 composer,则使用此命令。
步骤 2:启用扩展包
然后,通过在项目的 app/AppKernel.php 文件中添加以下行来启用扩展包
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new Coosos\TagBundle\CoososTagBundle(),
);
// ...
}
// ...
}
步骤 3:在数据库中插入标签实体
使用此命令在数据库中插入标签实体
$ php bin/console doctrine:schema:update -f
用法
实体中的标签字段
namespace AppBundle\Entity;
use Coosos\TagBundle\Model\Taggable\TaggableTrait;
class Actuality {
use TaggableTrait;
}
表单类型
要创建标签字段,您必须使用扩展包提供的字段类型
use Coosos\TagBundle\Form\Type\TagsType;
...
$builder->add("tags", TagsType::class);
选项
配置列表
用法
$builder->add("tags", TagsType::class, [
...,
"coosos_tag_auto_complete" => false,
"coosos_tag_persist_new" => false,
"coosos_tag_category" => "House"
]);
路由
您必须包含指向扩展包控制器的路由
# app/config/routing.yml
tag:
resource: "@CoososTagBundle/Controller/"
type: annotation
表单主题
您必须在项目中包含 jQuery tagEditor
twig:
form_themes:
- "CoososTagBundle:Form:fields.html.twig"
自动完成
自动完成使用 jQuery UI Autocomplete 库