use Doctrine\ORM\EntityManager; use MyApp\Entity\User; // Get the EntityManager $entityManager = ... // Create a new User object $user = new User(); $user->setUsername('alice'); $user->setPassword('secret'); // Persist the User object to the database $entityManager->persist($user); $entityManager->flush();
// Get an existing User object $user = $entityManager->getRepository(User::class)->find(1); // Update its properties $user->setPassword('newSecret'); // Persist the changes to the database $entityManager->flush();
// Get all User objects where the username is 'alice' $users = $entityManager->getRepository(User::class)->findBy(['username' => 'alice']); // Print out the results foreach ($users as $user) { echo $user->getUsername() . "\n"; }In these examples, we can see that the package library is Doctrine ORM.