我正在使用Symfony 3.4和api-platform构建API。我希望在我的实体上使用软删除。我已经安装了DoctrineExtensions
和StofDoctrineExtensionsBundle
。
config.yml
:
doctrine:
dbal:
connections:
default:
[…]
orm:
entity_managers:
default:
naming_strategy: doctrine.orm.naming_strategy.underscore
connection: default
mappings:
[…]
filters:
softdeleteable:
class: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter
enabled: true
我的实体:
<?php
namespace AppBundle\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* MyEntity
*
* @ORM\Table(name="MyEntity", schema="MyEntity")
* @ORM\Entity(repositoryClass="AppBundle\Repository\MyEntityRepository")
* @Gedmo\SoftDeleteable(fieldName="deletedAt")
* @ApiResource
*/
class MyEntity
{
/**
* @var \DateTime
* @ORM\Column(name="deleted_at", type="datetime")
*/
private $deletedAt;
[…]
这个不起作用。 我知道我需要配置某些东西(即事件管理器),但我不知道如何操作。在尝试创建实体时,以下是我收到的错误消息: "Listener“ SoftDeleteableListener”未添加到EventManager中!" 我认为我已经按照页面上的说明完成了所有步骤:StofDoctrineExtensionsBundle文档。任何帮助将不胜感激。