Hak*_*kim 7 soft-delete symfony doctrine-extensions api-platform.com
我正在使用Symfony 3.4和api平台构建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
Run Code Online (Sandbox Code Playgroud)
而我的实体:
<?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;
[…]
Run Code Online (Sandbox Code Playgroud)
这是行不通的。我知道我需要配置一些东西(即EventManager),但我不知道如何做。这是我尝试创建实体时遇到的错误
Listener "SoftDeleteableListener" was not added to the EventManager!
我认为我已经完成了该页面说明的所有内容:StofDoctrineExtensionsBundle文档
任何帮助将不胜感激。
在您的计算机上尝试以下配置 config.yml
doctrine:
orm:
entity_managers:
default:
naming_strategy: doctrine.orm.naming_strategy.underscore
connection: default
mappings:
[…]
filters:
softdeleteable:
class: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter
enabled: true
stof_doctrine_extensions:
default_locale: %locale%
orm:
default:
softdeleteable: true
Run Code Online (Sandbox Code Playgroud)
注意:我的配置如下所示:
orm:
auto_generate_proxy_classes: "%kernel.debug%"
entity_managers:
default:
auto_mapping: true
filters:
softdeleteable:
class: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter
enabled: true
Run Code Online (Sandbox Code Playgroud)
似乎您正在自定义自己,mappings因此请确保正确地自动加载SoftDeleteable类。
| 归档时间: |
|
| 查看次数: |
933 次 |
| 最近记录: |