Created
May 19, 2014 19:57
-
-
Save anonymous/c2b29c105719fe8cfe17 to your computer and use it in GitHub Desktop.
Controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function createAction(Request $request) { | |
$user = $this->get('security.context')->getToken()->getUser(); | |
$book = new Book(); | |
$form = $this->createForm(new BookType($user->getId()), $book); | |
$form->handleRequest($request); | |
if($form->isValid()) { | |
$book->upload(); | |
$em = $this->getDoctrine()->getManager(); | |
$em->persist($book); | |
$em->flush(); | |
$covers = $request->files->get('covers'); | |
foreach ($covers as $cover) { | |
$coverObj = new BookCover(); | |
$coverObj->setFile($cover); | |
$coverObj->setBook($book); | |
$coverObj->upload(); | |
$em->persist($coverObj); | |
} | |
$em->flush(); | |
return $this->redirect($this->generateUrl('matiit_book_homepage')); | |
} | |
return $this->render('MatiitBookBundle:Book:new.html.twig', ['form' => $form->createView()]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment