當前位置: 首頁>>代碼示例>>PHP>>正文


PHP FormFactory::create方法代碼示例

本文整理匯總了PHP中Symfony\Component\Form\FormFactory::create方法的典型用法代碼示例。如果您正苦於以下問題:PHP FormFactory::create方法的具體用法?PHP FormFactory::create怎麽用?PHP FormFactory::create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Form\FormFactory的用法示例。


在下文中一共展示了FormFactory::create方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: resolveItemToAdd

 /**
  * {@inheritdoc}
  */
 public function resolveItemToAdd(Request $request)
 {
     /*
      * We're getting here product set id via query but you can easily override route
      * pattern and use attributes, which are available through request object.
      */
     if ($id = $request->query->get('id')) {
         if ($product_set = $this->productSetManager->findSet($id)) {
             /*
              * To have it flexible, we allow adding single item by GET request
              * and also user can provide desired quantity by form via POST request.
              */
             $item = $this->itemManager->createItem();
             $item->setProductSet($product_set);
             if ('POST' === $request->getMethod()) {
                 $form = $this->formFactory->create('chewbacca_cart_item');
                 $form->setData($item);
                 $form->bindRequest($request);
                 if (!$form->isValid()) {
                     return false;
                 }
             }
             return $item;
         }
     }
 }
開發者ID:hd-deman,項目名稱:Chewbacca,代碼行數:29,代碼來源:ItemResolver.php

示例2: boxAction

 /**
  * @Template(":Todo/Search:box.html.twig")
  * @return array
  */
 public function boxAction(Request $request)
 {
     $search = new TodoList();
     $form = $this->formFactory->create('todo_list', $search);
     $form->handleRequest($request);
     return ['form' => $form->createView()];
 }
開發者ID:polidog,項目名稱:symfony_sample_todo,代碼行數:11,代碼來源:SearchController.php

示例3: postGameAction

 public function postGameAction(Request $request)
 {
     $uuid = $this->uuidGenerator->generate();
     $gameStartCommand = new GameStartCommand($uuid, "hup");
     $form = $this->formFactory->create(new GameStartType(), $gameStartCommand);
     $this->handleForm($request, $form, $uuid, $gameStartCommand);
 }
開發者ID:weemen,項目名稱:hangman_lennard,代碼行數:7,代碼來源:DefaultController.php

示例4: getLoginForm

 /**
  * @param null $data
  * @param array $options
  * @return \Symfony\Component\Form\Form
  */
 public function getLoginForm($data = null, array $options = [])
 {
     $options['last_username'] = $this->authenticationUtils->getLastUsername();
     if (!array_key_exists('action', $options)) {
         $options['action'] = $this->router->generate('security_login_check');
     }
     return $this->formFactory->create(LoginType::class, $data, $options);
 }
開發者ID:ampisoft,項目名稱:user-bundle,代碼行數:13,代碼來源:FormManager.php

示例5: createAction

 /**
  * @Route("/users/new", name="user_new")
  * @Template("BigfishUserBundle:Default:form.html.twig")
  */
 public function createAction(Request $request)
 {
     $user = $this->_security->getToken()->getUser();
     $entity = $this->_userManager->createUser();
     $form = $this->_formFactory->create(new UserType(), $entity);
     //        $this->_formFactory->create(, $data, $options);
     return array('form' => $form->createView());
 }
開發者ID:BigfishCMF,項目名稱:UserBundle,代碼行數:12,代碼來源:DefaultController.php

示例6: createForm

 /**
  * Create form for role manipulation
  *
  * @param Role $role
  * @return FormInterface
  */
 public function createForm(Role $role)
 {
     foreach ($this->privilegeConfig as $configName => $config) {
         $this->privilegeConfig[$configName]['permissions'] = $this->aclManager->getPrivilegeRepository()->getPermissionNames($config['types']);
     }
     $this->form = $this->formFactory->create(new ACLRoleType($this->privilegeConfig), $role);
     return $this->form;
 }
開發者ID:noglitchyo,項目名稱:pim-community-dev,代碼行數:14,代碼來源:AclRoleHandler.php

示例7: shouldNotBindInvalidValue

    /**
     * @test
     */
    public function shouldNotBindInvalidValue()
    {
        $form = $this->formFactory->create('payum_payment_factories_choice');

        $form->submit('invalid');

        $this->assertNull($form->getData());
    }
開發者ID:xxspartan16,項目名稱:BMS-Market,代碼行數:11,代碼來源:PaymentFactoriesChoiceTypeTest.php

示例8: postMenucardsAction

 /**
  * @ApiDoc(
  *  description="Create a new Object",
  *  formType="DinnerTime\UserInterface\RestBundle\Form\MenuCardType"
  * )
  * @param Request    $request
  * @param Restaurant $restaurant
  *
  * @return View
  */
 public function postMenucardsAction(Request $request, Restaurant $restaurant)
 {
     $form = $this->formFactory->create(new MenuCardType(), new AddNewMenuCardToRestaurantCommand($restaurant));
     $form->submit($request->request->all());
     if ($form->isValid()) {
         $this->useCase->handle($form->getData());
         return View::create($form->getData(), Codes::HTTP_CREATED);
     }
     return View::create($form);
 }
開發者ID:partikus,項目名稱:DinnerTime,代碼行數:20,代碼來源:MenuCardsController.php

示例9: saveAction

 /**
  * @Route("/", name="category_registration_save")
  * @Method("post")
  */
 public function saveAction(Request $request)
 {
     $form = $this->form_factory->create('category');
     $form->handleRequest($request);
     if ($form->isValid()) {
         $this->service->add($form->getData());
         return $this->redirect($this->generateUrl('app_admin_category_complete'));
     }
     return $this->render('Admin/Category/Registration/index.html.twig', ['form' => $form->createView()]);
 }
開發者ID:ffff5912,項目名稱:Blog,代碼行數:14,代碼來源:CategoryRegistrationController.php

示例10: testInvalidTest

 public function testInvalidTest()
 {
     $twig = new \Twig_Environment(new \Twig_Loader_Array(array('template' => '{{ form is invalid ? 1 : 0 }}')));
     $twig->addExtension(new FormExtension());
     $formWithError = $this->formFactory->create('text');
     $formWithError->addError(new FormError('test error'));
     $this->assertEquals('1', $twig->render('template', array('form' => $formWithError->createView())));
     $formWithoutError = $this->formFactory->create('text');
     $this->assertEquals('0', $twig->render('template', array('form' => $formWithoutError->createView())));
 }
開發者ID:Charlie-Lucas,項目名稱:InfiniteFormBundle,代碼行數:10,代碼來源:FormExtensionTest.php

示例11: indexPostAction

 /**
  * @Route("/")
  * @Method("post")
  */
 public function indexPostAction(Request $request)
 {
     $form = $this->form_factory->create('blog_article');
     $form->handleRequest($request);
     if ($form->isValid()) {
         $this->service->add($form->getData());
         return $this->redirect($this->generateUrl('app_admin_blogpost_complete'));
     }
     return $this->render('Admin/Blog/index.html.twig', ['form' => $form->createView()]);
 }
開發者ID:ffff5912,項目名稱:Blog,代碼行數:14,代碼來源:BlogPostController.php

示例12: editPostAction

 /**
  * @Route("/{id}", name="category_edit_post")
  * @ParamConverter("category", class="AppBundle:Category")
  * @Method("post")
  */
 public function editPostAction(Request $request, Category $category)
 {
     $form = $this->form_factory->create('category', $category);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $this->service->update();
         return $this->redirect($this->generateUrl('admin_category'));
     }
     return $this->render('Admin/Category/Registration/index.html.twig', ['form' => $form->createView()]);
 }
開發者ID:ffff5912,項目名稱:Blog,代碼行數:15,代碼來源:CategoryEditController.php

示例13: createAction

 /**
  * @Route("comment/{id}")
  * @ParamConverter("blog", class="AppBundle:BlogArticle")
  * @Method("post")
  */
 public function createAction(Request $request, BlogArticle $blog)
 {
     $comment = new Comment($blog);
     $form = $this->form_factory->create('comment', $comment);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $this->service->add($comment);
         return $this->redirect($this->generateUrl('app_blog_show', ['id' => $blog->getId()]));
     }
     return $this->render('Comment/form.html.twig', ['form' => $form->createView(), 'comment' => $comment]);
 }
開發者ID:ffff5912,項目名稱:Blog,代碼行數:16,代碼來源:CommentController.php

示例14: saveAction

 /**
  * @Route()
  * @Method("POST")
  *
  * @param Request $request
  * @return RedirectResponse
  */
 public function saveAction(Request $request)
 {
     $form = $this->formFactory->create('todo');
     $form->handleRequest($request);
     if ($form->isValid()) {
         $this->addTodo->run($form->getData());
         $this->notification->info('タスクを登録しました');
     } else {
         $this->notification->danger('タスクの登録に失敗しました');
     }
     return new RedirectResponse($this->router->generate('app_todo_default_index'));
 }
開發者ID:polidog,項目名稱:symfony_sample_todo,代碼行數:19,代碼來源:AddController.php

示例15: newAction

 /**
  * @Route("/newsletter/new", name="newsletter_new")
  *
  * @return Response
  *
  * @throws \Exception
  * @throws \Twig_Error
  */
 public function newAction(Request $request)
 {
     $resolvedForm = $this->formFactory->create(new NewsletterCampaignFormType());
     if ($request->isMethod("POST")) {
         $resolvedForm->handleRequest($request);
         if ($resolvedForm->isValid()) {
             $newsletterCampaign = $resolvedForm->getData();
             $this->newsletterCampaignManager->save($newsletterCampaign);
             $this->session->getFlashBag()->add('message', 'Saved!');
         }
     }
     return new Response($this->twig->render('AppBundle:Newsletter:new.html.twig', array('form' => $resolvedForm->createView(), '')));
 }
開發者ID:radudemetrescu,項目名稱:symfony,代碼行數:21,代碼來源:NewsletterController.php


注:本文中的Symfony\Component\Form\FormFactory::create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。