Symfony2 Entity Manager - Basic Operations
Some easy snippets ...
-
howto get the EM :
$em = $this->get('doctrine')->getEntityManager();
-
howto quick find:
$this->getDoctrine()->getRepository('DemoUserBundle:User')->find(1);
-
persist data :
$user = new User();
$user->setName("asd");
$em->persist($user);
try {
$em->flush();
} catch (\Exception $exc) {
//something...
}
Note: \Exception and NOT Exception.
Written by pleone
Related protips
2 Responses
Since Symfony 2.1 you should use getManager() instead of getEntityManager().
over 1 year ago
·
thnks for quick tip (y)
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#