How I can get the current user into my entity classes?

后端 未结 2 1512
甜味超标
甜味超标 2021-01-21 22:57

I am developing my first Symfony 4 application and I migrating from Symfony 2+ and symfony 3+.

Right now I am developing a back-end and all of my entity classes have a <

2条回答
  •  孤街浪徒
    2021-01-21 23:25

    You probably do not want to reinvent the wheel. There is the Blameable Doctrine Extension that already does that. You can install it with :

    composer require antishov/doctrine-extensions-bundle
    

    As there is already a recipe to configure it. Then you can activate the extension and then use it with something like :

    Specific documentation for the Blameable extension can be found here

    use Gedmo\Mapping\Annotation as Gedmo;
    
    class Post {
    
      /**
      * @var User $createdBy
      *
      * @Gedmo\Blameable(on="create")
      * @ORM\ManyToOne(targetEntity="App\Entity\User")
      */
      private $createdBy;
    
    }
    

提交回复
热议问题