symfony - Doctrine postPersist 事件已弃用 getEntity 函数

标签 symfony doctrine-orm doctrine

在 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/

相关文章:

php - 左连接的 MySQL/doctrine 问题

没有关系的 Symfony 实体

mysql - 将 PHPExcel_IOFactory 添加到 symfony 项目

php - 将 HWIOAuthBundle 与 FOSUserBundle 一起使用时出现 "Username could not be found"错误

database - 如何在 Symfony 4 中更新数据库?

php - Symfony 4、Doctrine 和 AWS RDS 只读副本使用

php - 如何在 Symfony 2.8 中使用 PHP 5.6 可变函数参数?

php - 如何在 LeftJoin querybuilder 中进行选择查询

html - Symfony2,学说扩展树 : Generating a "tree"-like dropdown Select list

postgresql - Doctrine 和 Postgresql,从数据库问题生成模型