title: Symfony 2: Error: Call to a member function has() on a non-object from Controller
body: <p>Here's my Controller A:</p>
  
  <pre><code>&lt;?php
  
  namespace MonitoringBundle\Controller;
  
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use Symfony\Component\HttpFoundation\Response;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  
  use Doctrine\ORM\Query\ResultSetMapping;
  
  use MonitoringBundle\Entity\MarketplaceShop;
  
  use MonitoringBundle\Controller\BController;
  
  class AController extends Controller
  {
      /**
       * @Route("/A")
       * @Template()
       */
      public function AAction()
      {
          $B = new BController;
  
          $response = $B-&gt;BAction();
  
          return $this-&gt;render('MonitoringBundle:Default:index.html.twig', array('BVar' =&gt; $response));
      }
  }
  ?&gt;
  </code></pre>
  
  <p>And thats Controller B:</p>
  
  <pre><code>&lt;?php
  
  namespace MonitoringBundle\Controller;
  
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use Symfony\Component\HttpFoundation\Response;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  
  use Doctrine\ORM\Query\ResultSetMapping;
  
  use MonitoringBundle\Entity\MarketplaceShop;
  
  class BController extends Controller
  {
      /**
       * @Route("/B")
       * @Template()
       */
      public function BAction()
      {
  
          $id     = 'A2WPX7PK44TEBQ';
          $em     = $this-&gt;getDoctrine()-&gt;getManager();
          $shop   = $em-&gt;getRepository('MonitoringBundle:MarketplaceShop')
                       -&gt;findOneByUniqueShopId($id);
          if (!$shop) {
              // do something
              return new Response('Shop does not exist.');
          } else {
              // do something else
              return new Response('Shop exists!');
          }
      }
  
  }
  ?&gt;
  </code></pre>
  
  <p>When I call <a href="http://example.com/B" rel="nofollow">http://example.com/B</a>, all is fine and I get a response:</p>
  
  <blockquote>
    <p>Shop does not exist.</p>
  </blockquote>
  
  <p>But when I call <a href="http://example.com/A" rel="nofollow">http://example.com/A</a>, I get an error:</p>
  
  <blockquote>
    <p>Error: Call to a member function has() on a non-object
    500 Internal Server Error - FatalErrorException</p>
  </blockquote>
  
  <p><strong>Stack Trace:
  in vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php at line 291</strong></p>
  
  <pre><code>public function getDoctrine()
  {
  if (!$this-&gt;container-&gt;has('doctrine')) {
  throw new \LogicException('The DoctrineBundle is not registered in your application.');
  }
  </code></pre>
  
  <p>Why does it work with /B/ but not with /A/?</p>