Пример #1
0
 /**
  * @Route("/add", name="estimate_add")
  * @Template("SiwappEstimateBundle:Estimate:edit.html.twig")
  */
 public function addAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $estimate = new Estimate();
     $estimate->addItem(new Item());
     $terms = $em->getRepository('SiwappConfigBundle:Property')->get('legal_terms');
     if ($terms) {
         $estimate->setTerms($terms);
     }
     $form = $this->createForm(EstimateType::class, $estimate, ['action' => $this->generateUrl('estimate_add')]);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em->persist($estimate);
         $em->flush();
         $this->addTranslatedMessage('flash.added');
         return $this->redirect($this->generateUrl('estimate_edit', array('id' => $estimate->getId())));
     }
     return array('form' => $form->createView(), 'entity' => $estimate, 'currency' => $em->getRepository('SiwappConfigBundle:Property')->get('currency'));
 }