Doctrine postPersist事件不推荐使用getEntity函数

hel*_*s.m 2 doctrine symfony doctrine-orm

在创建Doctrine postPersistEventListener 之后的Symfony中,我的IDE指向该$args->getEntity()行; 由于被弃用,我不知道如何解决这个问题,因为它与版本2.8Symfony文档中的代码相同

IDE PhpStorm的屏幕截图:https://image.prntscr.com/image/tT4zAlXkQMOxqvo6TLblUg.png

码:

public function postPersist(LifecycleEventArgs $args)
{
    $entity = $args->getEntity();

    // ...
}
Run Code Online (Sandbox Code Playgroud)

Ath*_*hos 6

在你正在使用的eventlistener类中,我猜你设置了坏类.

use Doctrine\Common\Persistence\Event\LifecycleEventArgs; -> the getEntity() method is deprecated.
Run Code Online (Sandbox Code Playgroud)

你应该使用:

use Doctrine\ORM\Event\LifecycleEventArgs;
Run Code Online (Sandbox Code Playgroud)