$user = new User(); $user->setName('John Doe'); $user->setEmail('johndoe@example.com'); $entityManager->persist($user); $entityManager->flush();
$user = $entityManager->find('User', 1); $user->setName('Jane Doe'); $entityManager->flush();
$users = $entityManager->getRepository('User')->findBy(array('status' => 'active')); foreach ($users as $user) { echo $user->getName(); }This code uses the repository pattern to query for all active User entities and loop through them to print out their names. Overall, the entityManager provides a powerful abstraction layer for interacting with databases in PHP and can be extended using a variety of package libraries, including Doctrine.