Skip to content

Instantly share code, notes, and snippets.

Created May 19, 2014 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/c2b29c105719fe8cfe17 to your computer and use it in GitHub Desktop.
Save anonymous/c2b29c105719fe8cfe17 to your computer and use it in GitHub Desktop.
Controller
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