title: Save user's ID in database with Symfony 2.6
body: <p>still getting to grips with Symfony so please excuse me if this is already asked. I don't quite understand how to send data to forms to be processed properly so am need of a bit of guidance.</p>
  
  <p>My issue is i wish to save my logged in user's ID into the database when they are creating a new gecko (so that this gecko's profile shows for only this user logged in). I am using FOSUserBundle by the way.</p>
  
  <p>I know i can get the current user's id by using something like <code>$user = $this-&gt;getUser()-&gt;getId();</code> However, i would like to save this into the database.</p>
  
  <p>createAction:</p>
  
  <pre><code>public function createAction(Request $request)
      {
          $entity = new Gecko();
          $form = $this-&gt;createCreateForm($entity);
          $form-&gt;handleRequest($request);
  
          if ($form-&gt;isValid()) {
              $em = $this-&gt;getDoctrine()-&gt;getManager();
              $em-&gt;persist($entity);
              $em-&gt;flush();
  
              return $this-&gt;redirect($this-&gt;generateUrl('gecko_show', array('name' =&gt; $entity-&gt;getName())));
          }
  
          return array(
              'entity' =&gt; $entity,
              'form'   =&gt; $form-&gt;createView(),
          );
      }
  </code></pre>
  
  <p>GeckoType:</p>
  
  <pre><code>&lt;?php
  
  namespace Breedr\GeckoBundle\Form;
  
  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\Form\FormBuilderInterface;
  use Symfony\Component\OptionsResolver\OptionsResolverInterface;
  
  class GeckoType extends AbstractType
  {
      /**
       * @param FormBuilderInterface $builder
       * @param array $options
       */
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder
              -&gt;add('name')
              -&gt;add('aquisitionDate')
              -&gt;add('morph')
              -&gt;add('sex', 'choice', array(
                  'choices' =&gt; array(
                      'Male' =&gt; 'Male',
                      'Female' =&gt; 'Female'
                  )
              ))
              -&gt;add('genetics')
              -&gt;add('bio')
              -&gt;add('bred', 'checkbox', array(
                  'required' =&gt; false
              ))
              -&gt;add('hatchling', 'checkbox', array(
                  'required' =&gt; false
              ))
              -&gt;add('clutch', 'text', array(
                  'data' =&gt; 0,
                  'required' =&gt; false
              ))
              -&gt;add('imageFile', 'file', array(
                  'required' =&gt; false
              ))
              -&gt;add('user_id', 'hidden', array(
                  'data' =&gt; $user,
              ))
          ;
      }
  
      /**
       * @param OptionsResolverInterface $resolver
       */
      public function setDefaultOptions(OptionsResolverInterface $resolver)
      {
          $resolver-&gt;setDefaults(array(
              'data_class' =&gt; 'Breedr\GeckoBundle\Entity\Gecko'
          ));
      }
  
      /**
       * @return string
       */
      public function getName()
      {
          return 'breedr_geckobundle_gecko';
      }
  }
  </code></pre>
  
  <p>I would really appreciate any help with this. I just can't understand how the data is used/sent. Thanks in advance :)</p>
  
  <p>Andy</p>