使用 Doctrine 扩展可与 API 平台软删除



我正在用Symfony 3.4和api-platform构建一个API。我想对我的实体使用软删除。我已经安装了DoctrineExtensionsStofDoctrineExtensionsBundle.

config.yml

doctrine:
dbal:
connections:
default:
[…]
orm:
entity_managers:
default:
naming_strategy: doctrine.orm.naming_strategy.underscore
connection: default
mappings:
[…]
filters:
softdeleteable:
class: GedmoSoftDeleteableFilterSoftDeleteableFilter
enabled: true

和我的实体:

<?php
namespace AppBundleEntity;
use ApiPlatformCoreAnnotationApiResource;
use DoctrineORMMapping as ORM;
use GedmoMappingAnnotation as Gedmo;
/**
* MyEntity
*
* @ORMTable(name="MyEntity", schema="MyEntity")
* @ORMEntity(repositoryClass="AppBundleRepositoryMyEntityRepository")
* @GedmoSoftDeleteable(fieldName="deletedAt")
* @ApiResource
*/
class MyEntity
{
/**
* @var DateTime
* @ORMColumn(name="deleted_at", type="datetime")
*/
private $deletedAt;
[…]

这是行不通的。我知道我需要配置一些东西(即事件管理器(,但我不知道如何配置。 这是我尝试创建实体时遇到的错误

Listener "SoftDeleteableListener" was not added to the EventManager!

我想我已经完成了该页面解释的所有内容:StofDoctrine扩展捆绑包文档

任何帮助将不胜感激。

config.yml尝试以下配置

doctrine:
orm:
entity_managers:
default:
naming_strategy: doctrine.orm.naming_strategy.underscore
connection: default
mappings:
[…]
filters:
softdeleteable:
class: GedmoSoftDeleteableFilterSoftDeleteableFilter
enabled: true
stof_doctrine_extensions:
default_locale: %locale%
orm:
default:
softdeleteable: true

注意:我的配置如下所示:

orm:
auto_generate_proxy_classes: "%kernel.debug%"
entity_managers:
default:
auto_mapping: true
filters:
softdeleteable:
class: GedmoSoftDeleteableFilterSoftDeleteableFilter
enabled: true

似乎您正在自定义mappings因此请确保您正确自动加载了 SoftDeleteable 类。

最新更新