0

I have an entity called Item as above:

<?php

/**
 * Item
 * @ORM\Table(name="item")
 * @ORM\Entity
 */
class Item {

    /**
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

     /**
     * @var \Acme\UserBundle\Entity\User
     * ???
     */
    private $user;

    .....

How can I inject logged User object into $user property via annotation in the easiest way?

dextervip
  • 4,999
  • 16
  • 65
  • 93

1 Answers1

1

If you are trying to save the created/updated timestamps and the user who performed these actions with your entity ... this is called blameable and timestampable behavior!

Have a look at Knp\DoctrineBehaviors including blameable and timestampable behaviors. (PHP 5.4+ needed)

Gedmo\DoctrineExtensions also provides blameable and timestampable. (PHP >=5.3.2)

Nicolai Fröhlich
  • 51,330
  • 11
  • 126
  • 130