edumedia/tag-bundle
最新稳定版本:0.1.19
Composer 安装命令:
composer require edumedia/tag-bundle
包简介
README 文档
README
Rationale
Revival of https://github.com/FabienPennequin/FPNTagBundle for Symfony 6+ and PHP 8+.
Note: The main difference with fpn/tag-bundle is that taggable entities do not hold their tags, they're only available through the TagService.
How to
Install bundle
composer require edumedia/tag-bundle
Create Tag class
<?php // src/Entity/Tag.php namespace App\Entity; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use eduMedia\TagBundle\Entity\TagInterface; use eduMedia\TagBundle\Entity\TagTrait; #[ORM\Entity] #[ORM\Table(name: 'tag')] class Tag implements TagInterface { use TagTrait; #[ORM\OneToMany(mappedBy: 'tag', targetEntity: 'App\Entity\Tagging', fetch: 'EAGER')] protected ?Collection $tagging = null; }
Create Tagging class
<?php // src/Entity/Tagging.php namespace App\Entity; use Doctrine\ORM\Mapping as ORM; use eduMedia\TagBundle\Entity\TaggingInterface; use eduMedia\TagBundle\Entity\TaggingTrait; use eduMedia\TagBundle\Entity\TagInterface; #[ORM\Entity] #[ORM\Table(name: 'tagging')] class Tagging implements TaggingInterface { use TaggingTrait; #[ORM\Id] #[ORM\ManyToOne(targetEntity: 'App\Entity\Tag', inversedBy: 'tagging')] protected TagInterface $tag; }
Make entity taggable
Here is a User example:
<?php // src/Entity/User namespace App\Entity; use eduMedia\TagBundle\Entity\TaggableInterface; use eduMedia\TagBundle\Entity\TaggableTrait; class User implements /* (...) */ TaggableInterface { use TaggableTrait; // (...) }
Define service arguments
# config/services.yaml services: # (...) eduMedia\TagBundle\Service\TagService: arguments: - 'App\Entity\Tag' - 'App\Entity\Tagging'
Migrate, to create tables
bin/console make:migration bin/console doctrine:migrations:migrate
Install assets
bin/console assets:install
Features
- Most features are packed in
eduMedia\TagBundle\Service\TagService(not documented yet, but should be self-explanatory) - If
symfony/consoleis installed, aedumedia:tag:createcommand is available - If
symfony/twig-bundleis installed,tag_serviceis globally available - If
symfony/formis installed,eduMedia\TagBundle\Form\Type\TagTypeis available - If using
easycorp/easyadmin-bundle, aeduMedia\TagBundle\Admin\Field\TagFieldis available
TODO
- Automated tests (help appreciated)
统计信息
- 总下载量: 6.09k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-04-19