/** * {@inheritDoc} */ public function load(ObjectManager $manager) { $userAdmin = new Author('Angel', 'Barcia'); $userAdmin->setName('Angel'); $userAdmin->setSurname('Barcia'); $manager->persist($userAdmin); $manager->flush(); }
/** * @Route("/author", name="Author pflegen") */ public function authorAction() { $author = new Author(); $author->setName("Ali"); $author->setGender("Mann"); // ... do something to the $author object $validator = $this->get('validator'); $errors = $validator->validate($author); if (count($errors) > 0) { /* * Uses a __toString method on the $errors variable which is a * ConstraintViolationList object. This gives us a nice string * for debugging. */ $errorsString = (string) $errors; return new Response($errorsString); } else { $em = $this->getDoctrine()->getManager(); $em->persist($author); $em->flush(); } return new Response('The author is valid! Yes!'); }
/** * @param ArrayCollection $authors */ public function setAuthors($authors) { if (is_null($authors)) { $author = new Author(); $author->setName('N/A'); $this->authors = $author; } else { $this->authors = $authors; } }