title: How to call doctrine in an entity class using symfony
body: <p>Am using symfony framework for my application. And to save records in database I want call the $this->getDoctrine()->getManager(); method in my entity class. But when I did that it gave me the error:
  Call to undefined method getDoctrine(),</p>
  
  <p>Can some one tell me what is the right way to do this.</p>
  
  <p>My entity class is like:</p>
  
  <p>
  
  <p>namespace Acme\SuperbAppBundle\Entity;</p>
  
  <p>use Symfony\Component\DependencyInjection\Container;
  use Doctrine\ORM\Mapping as ORM;</p>
  
  <pre><code>class Users
  {
  
  
  /**
   * @var integer
   */
  private $id;
  
  /**
   * @var string
   */
  private $firstName;
  
  /**
   * @var string
   */
  
  /**
   * Get id
   *
   * @return integer 
   */
  public function getId()
  {
      return $this-&gt;id;
  }
  
  /**
   * Set firstName
   *
   * @param string $firstName
   * @return Users
   */
  public function setFirstName($firstName)
  {
      $this-&gt;firstName = $firstName;
  
      return $this;
  }
  
  /**
   * Get firstName
   *
   * @return string 
   */
  public function getFirstName()
  {
      return $this-&gt;firstName;
  }
  
  
  function __construct($firstName){
  
      $this-&gt;setFirstName($firstName);
  
  }
  
  function save(){
  
      $em = $this-&gt;getDoctrine()-&gt;getManager();
      $em-&gt;persist($create);
      $em-&gt;flush();
  }
  
  }
  </code></pre>
  
  <p>And my controller method is like:</p>
  
  <pre><code>   public function test(){
  
      $create = new Users('Rajat');
  
      $create-&gt;save();
  
   }
  </code></pre>