在 Symfony 中创建 Doctrine postPersist
EventListener 后,我的 IDE 指向 $args->getEntity()
行;由于已被弃用,我不知道如何解决这个问题,因为它与 Symfony docs for version 2.8 中的代码相同。
IDE PhpStorm 的屏幕截图:https://image.prntscr.com/image/tT4zAlXkQMOxqvo6TLblUg.png
代码:
public function postPersist(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
// ...
}
最佳答案
在你使用的 eventlistener 类中,我猜你设置了错误的类。
use Doctrine\Common\Persistence\Event\LifecycleEventArgs; -> the getEntity() method is deprecated.
你应该使用:
use Doctrine\ORM\Event\LifecycleEventArgs;
关于symfony - Doctrine postPersist 事件已弃用 getEntity 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45856933/