title: Getting the user id from logged in user in FOSUserBundle
body: <p>I am trying to create a task manager and I need to be able to get the user id of the user that is currently logged in so that when the task is created the user id is entered into the database as well. I can not get it to work it keeps telling me that the <code>call to undefined function getUser()</code> i did not think that I had to define it, I thought it was built in.</p>
  
  <p>Can someone help me fix this it would be much appreciated!</p>
  
  <p>here is the function that creates the task</p>
  
  <pre><code>&lt;?php
  
  namespace Starnes\TaskBundle\Controller;
  
  use Symfony\Component\HttpFoundation\Request;
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  use Starnes\TaskBundle\Entity\Task;
  use Starnes\TaskBundle\Form\TaskType;
  use Starnes\UserBundle\Entity\User;
  
  /**
   * Task controller.
   *
   * @Route("/task")
   */
  class TaskController extends Controller
  {
  
      /**
       * Lists all Task entities.
       *
       * @Route("/", name="task")
       * @Method("GET")
       * @Template()
       */
      public function indexAction()
      {
          $em = $this-&gt;getDoctrine()-&gt;getManager();
  
          $entities = $em-&gt;getRepository('StarnesTaskBundle:Task')-&gt;findAll();
  
          return array(
              'entities' =&gt; $entities,
          );
      }
      /**
       * Creates a new Task entity.
       *
       * @Route("/", name="task_create")
       * @Method("POST")
       * @Template("StarnesTaskBundle:Task:new.html.twig")
       * 
       */
      public function createAction(Request $request)
      {
          $user = new User();
          $userID = $user-&gt;getUser()-&gt;getId();
          $entity = new Task();
          $form = $this-&gt;createCreateForm($entity);
          $form-&gt;handleRequest($request);
  
          if ($form-&gt;isValid()) {
              $em = $this-&gt;getDoctrine()-&gt;getManager();
              $em-&gt;persist($entity);
              $entity-&gt;setUserId($userID);
              $em-&gt;flush();
  
              return $this-&gt;redirect($this-&gt;generateUrl('task_show', array('id' =&gt; $entity-&gt;getId())));
          }
  
          return array(
              'entity' =&gt; $entity,
              'form'   =&gt; $form-&gt;createView(),
          );
      }
  </code></pre>