title: Call to a member function get() when calling a doctrine 2 entity form the service locator
body: <p>I am new to Doctrine 2 and ZF2.</p>
  
  <p><strong>My problem:</strong> I go to the route <code>myPage/bnk</code> that instantiates the class <code>BnkController</code> and the method <code>indexAction</code> if I try to access the <code>getEntityManager</code> method <strong>from there it all works</strong>.  </p>
  
  <p>Now when I instantiate the class <code>DataManager</code> in the method <code>indexAction</code> and then I try to call the <code>getEntityManager</code> method inside the class <code>DataManager</code> I get <code>Fatal error: Call to a member function get() on a non-object</code>  which I dont understand why is happening if it is all working in the <code>BnkController</code></p>
  
  <p>Why I am getting this error when I try to get the doctrine <code>EntityManager</code> from the <code>getServiceLocator</code> inside the class <code>DataManager</code>? </p>
  
  <pre><code>class BnkController extends AbstractActionController
      {
          public function indexAction ()
          {
              $this-&gt;uploadCSVAction( "data/bnk.csv" );
          }
  
          public function uploadCSVAction ( $fileName )
          {
              $parseCSV = new CsvParser();
              $dataManager = new DataManager();
  
              // Transforms CSV into Array
              $CSVData = $parseCSV-&gt;parseCSV( $fileName );
  
              // Makes sure that we are only using the right transactions and no overlap is happening
              $CSVData = $dataManager-&gt;validateTransactions($CSVData,$parseCSV);
  
              $dataManager-&gt;saveCSVDataToDB( $CSVData );
  
          }
  
          /**
           * @return \Doctrine\ORM\EntityManager
           */
          protected function getEntityManager ()
          {
              /** @var \Doctrine\ORM\EntityManager $objectManager */
              $objectManager = $this
                  -&gt;getServiceLocator()
                  -&gt;get( 'Doctrine\ORM\EntityManager' );
  
              return $objectManager;
          }
  </code></pre>
  
  <p>DataManager</p>
  
  <pre><code>&lt;?php
  
  namespace Bnk\Controller;
  
  /**
   * Class DataManager
   *
   * @package Bnk\Controller
   */
  class DataManager {
  
      /**
       * @return \Bnk\Repository\Transaction
       */
      protected function getTransactionRepository ()
      {
          /** @var \Bnk\Repository\Transaction $repository */
          $repository = $this-&gt;getEntityManager()-&gt;getRepository( 'Bnk\Entity\Transaction' );
  
          return $repository;
      }
  
      /**
       * @return \Doctrine\ORM\EntityManager
       */
      protected function getEntityManager ()
      {
          /** @var \Doctrine\ORM\EntityManager $objectManager */
          $objectManager = $this
              -&gt;getServiceLocator()
              -&gt;get( 'Doctrine\ORM\EntityManager' );
  
          return $objectManager;
      }
  } 
  </code></pre>