edumedia / tag-bundle
0.1.19
2024-09-24 08:44 UTC
Requires
- php: >=8.0.2
- doctrine/orm: ^2.1|^3.2
- symfony/config: ^6.0|^7.0
- symfony/dependency-injection: ^6.0|^7.0
- symfony/http-kernel: ^6.0|^7.0
Requires (Dev)
- easycorp/easyadmin-bundle: ^4.1
- symfony/console: ^6.0|^7.0
- symfony/form: ^6.0|^7.0
README
理由
为 Symfony 6+ 和 PHP 8+ 复兴 https://github.com/FabienPennequin/FPNTagBundle。
注意:与 fpn/tag-bundle 的主要区别在于,可标记的实体不保留它们的标签,它们仅通过 TagService 可用。
如何使用
安装包
composer require edumedia/tag-bundle
创建标签类
<?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; }
创建标签化类
<?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; }
使实体可标记
以下是一个用户示例
<?php // src/Entity/User namespace App\Entity; use eduMedia\TagBundle\Entity\TaggableInterface; use eduMedia\TagBundle\Entity\TaggableTrait; class User implements /* (...) */ TaggableInterface { use TaggableTrait; // (...) }
定义服务参数
# config/services.yaml services: # (...) eduMedia\TagBundle\Service\TagService: arguments: - 'App\Entity\Tag' - 'App\Entity\Tagging'
迁移,以创建表
bin/console make:migration bin/console doctrine:migrations:migrate
安装资产
bin/console assets:install
功能
- 大多数功能都打包在
eduMedia\TagBundle\Service\TagService中(尚未文档化,但应具有自解释性) - 如果已安装
symfony/console,则可用edumedia:tag:create命令 - 如果已安装
symfony/twig-bundle,则tag_service在全局范围内可用 - 如果已安装
symfony/form,则可用eduMedia\TagBundle\Form\Type\TagType - 如果使用
easycorp/easyadmin-bundle,则可用eduMedia\TagBundle\Admin\Field\TagField
待办事项
- 自动测试(需要帮助)