title: 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.
  The error is FatalErrorException: Error: Call to a member function has() on a non-object in in vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php at line 291.</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>}</p>
  
  <p>This is the main controller </p>
  
  <pre><code>namespace Acme\IndexBundle\Controller;
  
  use Symfony\Component\HttpFoundation\Session\Session;
  use Symfony\Component\HttpFoundation\Request;
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  
  use Acme\IndexBundle\Entity\SlotmachineSpin;
  use Acme\IndexBundle\Entity\SlotmachineReels;
  use Acme\IndexBundle\Entity\SlotmachinePrizes;
  use Acme\IndexBundle\Slots\UsersSlots;
  use Acme\IndexBundle\Slots\SlotsMachineSlots;
  
  
  class SpinController extends Controller  {
  
  
      public function indexAction(Request $request)
      {
          $session = $request-&gt;getSession();
          $slotsmachine = new SlotsMachineSlots();
          //$request = Request::createFromGlobals();
          $_machineName = $request-&gt;request-&gt;get('machine_name');
          $machineName = $slotsmachine-&gt;GetMachineName((isset($_machineName)?$_machineName : "default" ));
          $_bet = $request-&gt;request-&gt;get('bet');
          $bet = (isset($_bet) ? $_bet : $slotsmachine-&gt;MinBet($machineName)); // Should always be set, but just in case.
          $bet = min(max($slotsmachine-&gt;MinBet($machineName), $bet), $slotsmachine-&gt;MaxBet($machineName));
          $_windowID = $request-&gt;request-&gt;get('windowID');
          $windowID = (isset($_windowID) ? $_windowID : "");
  
          // Validate
          $error = "";
          $userID = UsersSlots::LoggedUserID();
  
          try { //DB::BeginTransaction();
              $em = $this-&gt;getDoctrine()-&gt;getManager();
              $em-&gt;getConnection()-&gt;beginTransaction();
  
              if (!$userID) {
                  $error = 'loggedOut';
              } else if(!UsersSlots::HasEnoughCredits($userID, $bet)) {
                  $error = "You don't have enough credits for this bet";
              }
  
              if ($error != "") {
                  echo json_encode(array('success'=&gt;false, 'error'=&gt;$error));
                  return;
              }
  
              // Do the charging, spinning and crediting
              UsersSlots::DeductCredits($userID, $bet);
  
              UsersController::IncrementSlotMachineSpins($userID);
              $data = SlotsMachineSlots::Spin($userID, $machineName, $bet, $windowID);
  
              if ($data['prize'] != null) {
                  UsersSlots::IncreaseCredits($userID, $data['prize']['payoutCredits']);
                  UsersSlots::IncreaseWinnings($userID, $data['prize']['payoutWinnings']);
                  $data['lastWin'] = $data['prize']['payoutWinnings'];
              }
  
              $data['success'] = true;
  
              $userData = UsersSlots::GetUserData($userID);
              $data['credits'] = (float) $userData['credits'];
              $data['dayWinnings'] = (float) $userData['day_winnings'];
              $data['lifetimeWinnings'] = (float) $userData['lifetime_winnings'];
  
              echo json_encode($data);
  
              $em-&gt;getConnection()-&gt;commit();
          } catch (Exception $e) {
                  $em-&gt;getConnection()-&gt;rollback(); 
                  throw $e; 
              }
  
          // Sample responses that allow you to test your CSS and JS
          // Comment the entire try/catch block above, and uncomment one of these at a time.
  
          // Regular spin, no prize
          //echo json_encode(array('success' =&gt; true, 'reels' =&gt; array(1, 2.5, 3), 'prize' =&gt; null, 'credits' =&gt; 99, 'dayWinnings' =&gt; 10, 'lifetimeWinnings' =&gt; 500));
  
          // Prize, pays credits only
          //echo json_encode(array('success' =&gt; true, 'reels' =&gt; array(1, 2.5, 3), 'prize' =&gt; array('id' =&gt; 1, 'payoutCredits' =&gt; 10, 'payoutWinnings' =&gt; 0), 'credits' =&gt; 19, 'dayWinnings' =&gt; 00, 'lifetimeWinnings' =&gt; 500));
  
          // Prize, pays winnings only
          //echo json_encode(array('success' =&gt; true, 'reels' =&gt; array(1, 2.5, 3), 'prize' =&gt; array('id' =&gt; 2, 'payoutCredits' =&gt; 0, 'payoutWinnings' =&gt; 100), 'credits' =&gt; 9, 'dayWinnings' =&gt; 100, 'lifetimeWinnings' =&gt; 600));
  
          // Error (logged out)
          //echo json_encode(array('success' =&gt; false, 'error' =&gt; 'loggedOut'));
  
          // Error (other)
          //echo json_encode(array('success' =&gt; false, 'error' =&gt; 'You do not have enough credits for this spin'));
          //return new Response(json_encode(array('spinData' =&gt; $spinData)));
      }
  
  
  }
  </code></pre>
  
  <p>This is the service that is being used.</p>
  
  <pre><code>acme.controller.spin:
      class: Imaginer\IndexBundle\Controller\SpinController
      calls:
          - [setContainer, ["@service_container"]]
  </code></pre>
  
  <p>I am sure the problem is that the doctrine container is not present which is why I am having issues.</p>
  
  <p>Any help is appreciated. Thanks!</p>