kgfiba
Last Updated: February 25, 2016
·
2.095K
· pleone
Bug

Symfony2 Entity Manager - Basic Operations

Some easy snippets ...

  1. howto get the EM :

    $em = $this->get('doctrine')->getEntityManager();

  2. howto quick find:

    $this->getDoctrine()->getRepository('DemoUserBundle:User')->find(1);

  3. persist data :

    $user = new User();
    $user->setName("asd");
    $em->persist($user);
    try {
    $em->flush();
    } catch (\Exception $exc) {
    //something...
    }

Note: \Exception and NOT Exception.

Say Thanks
Respond

2 Responses
Add your response

5625
B85126b299ba8741fd1f79b41208adb0

Since Symfony 2.1 you should use getManager() instead of getEntityManager().

over 1 year ago ·
25729
A9aff76526cf602308c68d6b93c1f5eb

thnks for quick tip (y)

over 1 year ago ·