So rufen Sie die Lehre in einer entity-Klasse mit symfony

Bin mit symfony-framework für meine Anwendung. Und speichern die Datensätze in der Datenbank möchte ich aufrufen, die $this->getDoctrine()->getManager(); Methode in meine entity-Klasse. Aber als ich das Tat, es gab mir die Fehlermeldung:
Call to undefined method getDoctrine(),

Kann jemand mir sagen, was ist der richtige Weg, dies zu tun.

Meine entity-Klasse wird wie:

namespace Acme\SuperbAppBundle\Entität;

use Symfony\Component\DependencyInjection\Container;
use Doctrine\ORM\Mapping as ORM;

class Users
{


/**
 * @var integer
 */
private $id;

/**
 * @var string
 */
private $firstName;

/**
 * @var string
 */

/**
 * Get id
 *
 * @return integer 
 */
public function getId()
{
    return $this->id;
}

/**
 * Set firstName
 *
 * @param string $firstName
 * @return Users
 */
public function setFirstName($firstName)
{
    $this->firstName = $firstName;

    return $this;
}

/**
 * Get firstName
 *
 * @return string 
 */
public function getFirstName()
{
    return $this->firstName;
}


function __construct($firstName){

    $this->setFirstName($firstName);

}

function save(){

    $em = $this->getDoctrine()->getManager();
    $em->persist($create);
    $em->flush();
}

}

Und meine controller-Methode ist wie:

   public function test(){

    $create = new Users('Rajat');

    $create->save();

 }

InformationsquelleAutor Randhir | 2014-07-01

Schreibe einen Kommentar