gpt4 book ai didi

symfony - DoctrineExtensions SoftDeleteable : gedmo/doctrine-extensions 的配置条目

转载 作者:行者123 更新时间:2023-12-04 02:02:25 27 4
gpt4 key购买 nike

我正在尝试使用 softdelete gedmo/doctrine-extensions 的选项但出于某种原因,当我调用 romove() 时,数据库中的记录被删除而不是更新 deletedAt field 。

here , doc 告诉我们更新配置:

$config->addFilter('soft-deleteable', 'Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter');



这只是我尝试过的示例之一:
# app/config/config.yml
doctrine:
orm:
entity_managers:
default:
filters:
softdeleteable:
class: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter
enabled: true

引用资料(只是其中的一些):
  • DoctrineExtensions SoftDeleteable
  • http://knplabs.com/en/blog/gedmo-doctrine-extensions-on-symfony2
  • Can't enable SoftDeleteable in Symfony2 - Unrecognized options "filters"

  • 那么简单的问题,我如何在 config.yml 中配置它?

    Controller
    public function delete($id)
    {
    $profile = $this->profileRepository->findOneBy(['id' => $id]);

    if (!$profile instanceof Profile) {
    throw new ........
    }

    $this->entityManager->remove($profile);
    $this->entityManager->flush();

    return true;
    }

    实体
    use Gedmo\Mapping\Annotation as Gedmo;

    /**
    * @ORM\Entity()
    * @ORM\Table(name="profile")
    * @Gedmo\SoftDeleteable(fieldName="deletedAt")
    */
    class Profile
    {
    /**
    * @ORM\Column(name="deletedAt", type="datetime", nullable=true)
    */
    private $deletedAt;
    ......
    }

    COMPOSER.JSON
    "require": {
    "symfony/symfony": "2.6.*",
    "doctrine/orm": "~2.2,>=2.2.3",
    "doctrine/doctrine-bundle": "~1.2",
    "gedmo/doctrine-extensions": "2.3.*@dev",
    ......
    },

    配置.YML
    doctrine:
    dbal:
    default_connection: front
    connections:
    front:
    driver: %database_driver%
    host: %database_host%
    ........
    back:
    driver: %database_driver%
    host: %database_host%
    ........


    orm:
    auto_generate_proxy_classes: %kernel.debug%
    default_entity_manager: front

    entity_managers:
    front:
    connection: front
    mappings:
    MyWebsiteBundle:
    dir: Entity
    FOSUserBundle: ~

    back:
    connection: back

    映射信息:
    inanzzz@inanzzz:/var/www/html/local$ php app/console doctrine:mapping:info
    Found 8 mapped entities:
    [OK] My\Bundle\Entity\AbstractMerchantProfile
    [OK] My\Bundle\Entity\AbstractIntegration
    [OK] My\Bundle\Entity\APIConsumer
    [OK] My\Bundle\WebsiteBundle\Entity\User
    [OK] My\Bundle\WebsiteBundle\Entity\Profile
    [OK] My\Bundle\WebsiteBundle\Entity\Integration
    [OK] FOS\UserBundle\Model\Group
    [OK] FOS\UserBundle\Model\User

    最佳答案

    这就是我配置它的方式

    doctrine:
    dbal:
    driver: "%database_driver%"
    host: "%database_host%"
    port: "%database_port%"
    dbname: "%database_name%"
    user: "%database_user%"
    password: "%database_password%"
    charset: UTF8

    orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    auto_mapping: true
    filters:
    softdeleteable:
    class: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter
    enabled: true

    关于symfony - DoctrineExtensions SoftDeleteable : gedmo/doctrine-extensions 的配置条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29798674/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com