Php 条令生命周期回调不适用于EasyAdminBundle

Php 条令生命周期回调不适用于EasyAdminBundle,php,symfony,doctrine-orm,Php,Symfony,Doctrine Orm,我正在使用Symfony 4和EasyAdminBundle来创建一个简单的管理界面。我在尝试自动设置createdAt和updatedAt列的值时遇到了一些问题。在EasyAdmin中创建/更新实体时,不会调用已配置的条令生命周期回调。例如,这里有一个使用EasyAdmin管理的简单实体,请注意生命周期回调挂钩: <?php namespace App\Entity; /** * @ORM\Entity(repositoryClass="App\Repository\Product

我正在使用Symfony 4和EasyAdminBundle来创建一个简单的管理界面。我在尝试自动设置
createdAt
updatedAt
列的值时遇到了一些问题。在EasyAdmin中创建/更新实体时,不会调用已配置的条令生命周期回调。例如,这里有一个使用EasyAdmin管理的简单实体,请注意生命周期回调挂钩:

<?php

namespace App\Entity;

/**
 * @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
 * @ORM\HasLifecycleCallbacks
 */
class Product
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    // Additional column configuration removed for brevity

    /**
     * @ORM\Column(type="datetime")
     */
    private $createdAt;

    /**
     * @ORM\Column(type="datetime", nullable=true)
     */
    private $updatedAt;

    // Additional getters/setters removed for brevity

    public function getCreatedAt(): ?\DateTimeInterface
    {
        return $this->createdAt;
    }

    public function setCreatedAt(?\DateTimeInterface $createdAt): self
    {
        $this->createdAt = $createdAt;

        return $this;
    }

    public function getUpdatedAt(): ?\DateTimeInterface
    {
        return $this->updatedAt;
    }

    public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
    {
        $this->updatedAt = $updatedAt;

        return $this;
    }

    /**
     * @ORM\PrePersist
     */
    public function onPrePersist(): void
    {
        $this->createdAt = new \DateTime();
    }

    /**
     * @ORM\PreUpdate
     */
    public function onPreUpdate(): void
    {
        $this->updatedAt = new \DateTime();
    }
}
EasyAdminBundle是否绕过条令生命周期回调?若然,原因为何?如何在EasyAdminBundle管理的条令实体中利用条令生命周期回调

据我所知,有一些文档可以对
AdminController
执行类似的操作:

但同样,既然我们已经有了条令生命周期回调,为什么还要这样做呢。我的另一个问题是使用
AdminController
并扩展各种方法,
AdminController
中的
persistenty()
也从未被调用

我错过了什么


任何帮助都将不胜感激!干杯

我对easy admin bundle不是特别熟悉,但我找不到原因,也找不到为什么它们会破坏生命周期回调系统,也找不到代码说明它们会破坏生命周期回调系统。所以,除非我遗漏了什么(可能是这样),否则我会不知所措。除了可能。。。当您不使用dev时,清除和预热缓存可能会有所帮助。。。但除此之外,我没有任何想法。正如一个旁注——考虑使用<代码> GeMo/Trand扩展< /CODE>——这提供了(包括许多其他有用的东西)DB在属性上创建/更新的能力:我不太熟悉Apple Admin束,但我找不到原因,为什么他们会破坏生命周期回调系统,也没有代码说他们会。所以,除非我遗漏了什么(可能是这样),否则我会不知所措。除了可能。。。当您不使用dev时,清除和预热缓存可能会有所帮助。。。但除此之外,我没有任何想法。正如一个旁注——考虑使用<代码> GeMo/Trand扩展< /CODE>——这提供了(包括许多其他有用的东西)DB在属性上创建/更新的能力:
    <?php

    $product = new Product();
    $product->setTitle('Test Product');
    $product->setDescription('Test description');

    // Doctrine lifecycle callbacks work as expected
    $this->getDoctrine()->getManager()->persist($product);