Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To relate the user to the product you want to associate the two entities: <a href="http://symfony.com/doc/current/book/doctrine.html#entity-relationships-associations" rel="nofollow">http://symfony.com/doc/current/book/doctrine.html#entity-relationships-associations</a></p> <pre><code>/** * @ORM\ManyToOne(targetEntity="User", inversedBy="products") * @ORM\JoinColumn(name="user_id", referencedColumnName="id") * You may need to use the full namespace above instead of just User if the * User entity is not in the same bundle e.g FOS\UserBundle\Entity\User * the example is just a guess of the top of my head for the fos namespace though */ protected $user; </code></pre> <p>and for the automatic update field you may be after lifecyclecallbacks: <a href="http://symfony.com/doc/current/book/doctrine.html#lifecycle-callbacks" rel="nofollow">http://symfony.com/doc/current/book/doctrine.html#lifecycle-callbacks</a></p> <pre><code>/** * @ORM\Entity() * @ORM\HasLifecycleCallbacks() */ class Product { /** * @ORM\PreUpdate */ public function setCreatedValue() { $this-&gt;created = new \DateTime(); } } </code></pre> <h2>EDIT</h2> <p>This discussion talks about getting the container in the entity in which case you could then get the security.context and find the user id from that if you mean to associate the current user to the product they edited: <a href="https://groups.google.com/forum/?fromgroups#!topic/symfony2/6scSB0Kgds0" rel="nofollow">https://groups.google.com/forum/?fromgroups#!topic/symfony2/6scSB0Kgds0</a></p> <pre><code>//once you have the container you can get the session $user= $this-&gt;container-&gt;get('security.context')-&gt;getToken()-&gt;getUser(); $updated_at = $user-&gt;getId(); </code></pre> <p>Maybe that is what you are after, not sure it is a good idea to have the container in the entity though, could you not just set the user on the product in the update action in your product controller:</p> <pre><code>public function updateAction(){ //.... $user= $this-&gt;get('security.context')-&gt;getToken()-&gt;getUser(); $product-&gt;setUser($user) } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload