Aşağıdaki örnekte CRUD işlemlerinde entity manager ve doctrine repository kullanımını göreceğiz. Not: İsterseniz getManager() isterseniz de getEntityManager() kullanabilirsiniz.


Create


$em = $this->getDoctrine()->getEntityManager();
$person->setName('inanzzz');
$em->persist($person);
$em->flush();

Read


$repo = $this->getDoctrine()->getRepository('MyUserBundle:Person');
$person = $repo->findOneBy(['id' => $personId]);

Update


$em = $this->getDoctrine()->getEntityManager();
$repo = $em->getDoctrine()->getRepository('MyUserBundle:Person');
$person = $repo->findOneBy(['id' => $personId]);
$person->setName('inanzzz');
$em->flush();

Delete


$em = $this->getDoctrine()->getEntityManager();
$repo = $em->getDoctrine()->getRepository('MyUserBundle:Person');
$person = $repo->findOneBy(['id' => $personId]);
$em->remove($person);
$em->flush();