title: Using a repository outside of a controller in Symfony2
body: <p>I am currently using a function to get my repositories like so:</p>
  
  <pre><code>public function getRepositories()
  {
      // Tasks
      $tasks = $this-&gt;getDoctrine()
          -&gt;getRepository('Model:Task');
  
      // Task Info
      $taskInfos = $this-&gt;getDoctrine()
          -&gt;getRepository('Model:TaskInfo');
  
  
      return array(
          'tasks'             =&gt; $tasks,
          'taskInfos'         =&gt; $taskInfos,
      );
  }
  </code></pre>
  
  <p>So in my controller actions, I can just call some SQL like this:</p>
  
  <pre><code>$repositories = $this-&gt;getRepositories();
  $task = $repositories['tasks']-&gt;findOneById($id);
  </code></pre>
  
  <p>But now that I have a few controllers, I've noticed that I'm copying that same getRepositories() function into each which is not good as it's replicating the code repeatedly.</p>
  
  <p>What I want is to have like a helper class, and this could be one of the functions in that.</p>
  
  <p>But how do I do this, given the helper class won't be a controller and there for <code>$this-&gt;getDoctrine()</code> obviously wouldn't work?</p>
  
  <p>Thanks</p>