id; } public function getName() { return $this->name; } public function setName($name) { $this->name = $name; } public function getEmail() { return $this->email; } public function setEmail($email) { $this->email = $email; }}
setName("John Doe");$user->setEmail("john.doe@example.com");$entityManager->persist($user);$entityManager->flush();echo "Created User with ID " . $user->getId() . "\n";// find a user by ID$user = $entityManager->find("MyProject\Entity\User", 1);if ($user === null) { echo "User not found.\n"; exit(1);}echo sprintf("User: %s (%s)\n", $user->getName(), $user->getEmail());// update a user$user->setName("Jane Doe");$user->setEmail("jane.doe@example.com");$entityManager->flush();echo sprintf("Updated User: %s (%s)\n", $user->getName(), $user->getEmail());// delete a user$entityManager->remove($user);$entityManager->flush();echo "Deleted User with ID " . $user->getId() . "\n";