コード例 #1
0
 /**
  * @Route("/table/new", name="store_new")
  * @Method({"GET", "POST"})
  * @Template()
  */
 public function newAction(Request $request)
 {
     $app = $this->getApp($request);
     $appParams = $this->getExtensionAppParameters($request);
     $store = new Store();
     $store->setApp($app);
     $form = $this->createForm(new StoreType(), $store, array('action' => $this->generateUrl('store_new', $appParams), 'method' => 'POST'));
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($store);
         $em->flush();
         return $this->redirect($this->generateUrl('store_list', $appParams));
     }
     $data = ['store' => $store, 'form' => $form->createView(), 'appParams' => $appParams];
     return $data;
 }
コード例 #2
0
 protected function settingsAction(Request $request)
 {
     $app = $this->getApp($request);
     if (!$app->getStores()->count()) {
         $defaultStore = new Store();
         $defaultStore->setName('Default');
         $defaultStore->setApp($app);
         $app->addStore($defaultStore);
         $em = $this->getDoctrine()->getManager();
         $em->persist($defaultStore);
         $em->flush($defaultStore);
     }
     $form = $this->createForm(new ViewType($app), $this->getView($request));
     if ($request->getMethod() == 'POST') {
         $form->handleRequest($request);
         if ($form->isValid()) {
             $this->get('session')->getFlashBag()->add('success', 'Your changes were saved');
             $this->getDoctrine()->getManager()->flush();
         }
     }
     return ['form' => $form->createView(), 'appParams' => $this->getExtensionParameters($request)];
 }