title: Symfony: Call to a member function has() on null
body: <p>I am beginner in Symfony &amp; its already making me sick!</p>
  
  <p>This is my simple code:</p>
  
  <pre><code>&lt;?php
  
  namespace AppBundle\Controller;
  
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use Symfony\Component\HttpFoundation\Request;
  use AppBundle\Entity\Users;
  
  class ValidationController extends Controller
  {
      public function alreadyExists($email){
          $repository = $this-&gt;getDoctrine()-&gt;getRepository('AppBundle:Users');  //ERROR IN THIS LINE
          $user = $repository-&gt;findOneBy(array('email' =&gt; $email));
          if($user==NULL) return true;
          else return false;
      }
  }
  
  ?&gt;
  </code></pre>
  
  <p>When I call the function <code>alreadyExists</code> it is giving me this error:</p>
  
  <blockquote>
    <p>Error: Call to a member function has() on null in
    vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php
    (line 356)</p>
  </blockquote>
  
  <p>Not sure but I think it is failing to get doctrine. When I trace, the error actually occurs in <code>vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php</code> file on line 356, ie:</p>
  
  <pre><code>protected function getDoctrine()
      {
          if (!$this-&gt;container-&gt;has('doctrine')) {  ///LINE NO. 356
              throw new \LogicException('The DoctrineBundle is not registered in your application.');
          }
          return $this-&gt;container-&gt;get('doctrine');
      }
  </code></pre>
  
  <p>The exact same function works well if I cut-paste it in another controller, even though its the same code and the other controller has exact same <code>namespace</code> &amp; <code>use</code> statements.</p>
  
  <p>Please someone let me know what is this error &amp; why the heck is this happening?</p>