Question

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?

Was it helpful?

Solution

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)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top