コード例 #1
0
ファイル: LoadUserData.php プロジェクト: abarcia1/Galeria
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $userAdmin = new Author('Angel', 'Barcia');
     $userAdmin->setName('Angel');
     $userAdmin->setSurname('Barcia');
     $manager->persist($userAdmin);
     $manager->flush();
 }
コード例 #2
0
 /**
  * @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!');
 }
コード例 #3
0
ファイル: Book.php プロジェクト: sbernal93/books
 /**
  * @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;
     }
 }