title: FatalErrorException: Error: Call to a member function has() on a non-object
body: <p>I have a read a lot of topics on this and I can't seem to find a solution to my problem.  </p>
  
  <p>I feel like the problem is obvious and maybe I have just been staring at it too long.  </p>
  
  <p>The error is FatalErrorException: Error: Call to a member function has() on a non-object in /vagrant/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php line 198</p>
  
  <p>Looking at the error line, it says. </p>
  
  <pre><code>public function getDoctrine()
      {
          if (!$this-&gt;container-&gt;has('doctrine')) {
              throw new \LogicException('The DoctrineBundle is not registered in your application.');
          }
  
          return $this-&gt;container-&gt;get('doctrine');
      }
  </code></pre>
  
  <p>Here is my code...</p>
  
  <p>This is the main controller that is calling the DAO Controller </p>
  
  <pre><code>public function clickThroughAction(request $request, $hash)
      {
          if (isset($hash)) {
              $dbController = $this-&gt;get('database_controller');
              print_r($dbController-&gt;getReferralIdByHash($hash));
              return $this-&gt;redirect($this-&gt;generateUrl('home'));
          } else {
              return 0;
  
          }
      }
  </code></pre>
  
  <p>This is the service that is being used.  </p>
  
  <pre><code>services:
      database_controller:
          class:  Fuel\FormBundle\Controller\DatabaseController
  </code></pre>
  
  <p>This is the dao controller that is calling the database.  </p>
  
  <pre><code>public function getReferralIdByHash($hash)
      {
          $em = $this-&gt;getDoctrine()-&gt;getManager();
          $query = $em-&gt;createQuery(
              'Select u From FuelFormBundle:UserReferrals u WHERE u.user_hash = :hash'
          )-&gt;setParameter('hash', $hash);
  
          $referral = $query-&gt;getResult();
  
          if (!$referral) {
              throw $this-&gt;createNotFoundException(
                  'No product referral found'
              );
              $logger = $this-&gt;get('logger');
              $logger-&gt;info('I just got the logger');
              $logger-&gt;crit('An error occurred, hash for referrals is not recognized. current hash is: ' . $hash . " .");
              return $this-&gt;redirect($this-&gt;generateUrl('home'));
          }
  
          $clickThroughCount = $referral[0]-&gt;getClickThrough();
          $referral[0]-&gt;setClickThrough($clickThroughCount + 1);
          $em-&gt;flush();
          return $referral;
      }
  </code></pre>
  
  <p>I think the problem is that the doctrine container is not present which is why I am having issues.  I am not sure how to solve this.  </p>
  
  <p>Any help is appreciated.   Thanks! </p>
  
  <p>Edit</p>
  
  <hr>
  
  <p>Ok so here is what I changed. </p>
  
  <p>Main Controller stayed the same. </p>
  
  <p>DAO Controller a couple of things were added.  </p>
  
  <pre><code>class DatabaseController extends Controller{
      protected  $entityManager;
  
      public function __construct($entityManager) {
          $this-&gt;entityManager = $entityManager;
      }
  public function getReferralIdByHash($hash)
      {
          $em = $this-&gt;entityManager;
          $query = $em-&gt;createQuery(
              'Select u From FuelFormBundle:UserReferrals u WHERE u.user_hash = :hash'
          )-&gt;setParameter('hash', $hash);
  
          $referral = $query-&gt;getResult();
  
          if (!$referral) {
              throw $this-&gt;createNotFoundException(
                  'No product referral found'
              );
              $logger = $this-&gt;get('logger');
              $logger-&gt;info('I just got the logger');
              $logger-&gt;crit('An error occurred, hash for referrals is not recognized. current hash is: ' . $hash . " .");
              return $this-&gt;redirect($this-&gt;generateUrl('home'));
          }
  
          $clickThroughCount = $referral[0]-&gt;getClickThrough();
          $referral[0]-&gt;setClickThrough($clickThroughCount + 1);
          $em-&gt;flush();
          return $referral;
      }
  }
  </code></pre>
  
  <p>Service ended up looking like this </p>
  
  <pre><code>services:
       database_controller:
            class:  Fuel\FormBundle\Controller\DatabaseController
            arguments: ["@doctrine.orm.entity_manager"]
  </code></pre>