当前位置: 首页>>代码示例>>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;未经允许,请勿转载。