本文整理汇总了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;
}
}
}
示例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()];
}
示例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);
}
示例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);
}
示例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());
}
示例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;
}
示例7: shouldNotBindInvalidValue
/**
* @test
*/
public function shouldNotBindInvalidValue()
{
$form = $this->formFactory->create('payum_payment_factories_choice');
$form->submit('invalid');
$this->assertNull($form->getData());
}
示例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);
}
示例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()]);
}
示例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())));
}
示例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()]);
}
示例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()]);
}
示例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]);
}
示例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'));
}
示例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(), '')));
}