当前位置: 首页>>代码示例>>PHP>>正文


PHP Form::bind方法代码示例

本文整理汇总了PHP中Symfony\Component\Form\Form::bind方法的典型用法代码示例。如果您正苦于以下问题:PHP Form::bind方法的具体用法?PHP Form::bind怎么用?PHP Form::bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Form\Form的用法示例。


在下文中一共展示了Form::bind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: bindRequest

 /**
  * @param Request $request
  */
 public function bindRequest(Request $request)
 {
     $this->form->bind($request);
     foreach ($this->tabs as $tab) {
         $tab->bindRequest($request);
     }
 }
开发者ID:headonkeyboard,项目名称:KunstmaanBundlesCMS,代码行数:10,代码来源:TabPane.php

示例2: process

 /**
  * @param EntityManager $user
  *
  * @return bool
  */
 public function process(ProjetModel $projet)
 {
     $this->form->setData($projet);
     if ('POST' == $this->request->getMethod()) {
         $this->form->bind($this->request);
         if ($this->form->isValid()) {
             $projet->setUser($this->connectedUser);
             ############ Edit settings ##############
             $DestinationDirectory = __DIR__ . '/../../../../../web/uploads/';
             //specify upload directory ends with / (slash)
             $Quality = 90;
             //jpeg quality
             ##########################################
             //Let's check allowed $ImageType, we use PHP SWITCH statement here
             $ext = $projet->file->getMimeType();
             switch (strtolower($projet->file->getMimeType())) {
                 case 'image/png':
                     //Create a new image from file
                     $CreatedImage = imagecreatefrompng($projet->file->getRealPath());
                     break;
                 case 'image/gif':
                     $CreatedImage = imagecreatefromgif($projet->file->getRealPath());
                     break;
                 case 'image/jpeg':
                 case 'image/pjpeg':
                     $CreatedImage = imagecreatefromjpeg($projet->file->getRealPath());
                     break;
                 default:
                     die('Unsupported File!');
                     //output error and exit
             }
             // Crop and save image to upload directory
             $cropService = $this->cropper;
             $destImage = uniqid() . '.' . $projet->file->guessExtension();
             if (!$cropService->cropImage($projet->getX(), $projet->getY(), $projet->getW(), $projet->getH(), $DestinationDirectory . $destImage, $CreatedImage, $Quality, $projet->file->getMimeType())) {
                 die('Erreur lors du rognage de l\'image');
             }
             $projet->setPhoto($destImage);
             // Create entity project
             $entity = new Projet();
             $entity->setNomprojet($projet->getNomprojet());
             $entity->setDescription($projet->getDescription());
             $entity->setDuree($projet->getDuree());
             $entity->setDaterealisation($projet->getDaterealisation());
             $entity->setGains($projet->getGains());
             $entity->setFinancement($projet->getFinancement());
             $entity->setPhoto($projet->getPhoto());
             $entity->setCout($projet->getCout());
             $entity->setUser($projet->getUser());
             $this->entityManager->persist($entity);
             $this->entityManager->flush();
             return true;
         }
     }
     return false;
 }
开发者ID:WildCodeSchool,项目名称:projet-wiki_des_maires,代码行数:61,代码来源:ProjetHandler.php

示例3: process

 /**
  *
  * @return boolean
  */
 public function process()
 {
     $this->form->bind($this->request);
     if ($this->form->isValid()) {
         $formData = $this->form->getData();
         if ($name = (string) $formData->name) {
             $this->qb->andWhere($this->qb->expr()->like('a.name', ':name'))->setParameter('name', '%' . $name . '%');
         }
         return true;
     }
     return false;
 }
开发者ID:radutopala,项目名称:BlogBundle,代码行数:16,代码来源:AuthorFilterHandler.php

示例4: checkFilters

 /**
  * checkFilters
  * 
  * Build filters form
  * If the method POST filters are constructed and written to the session
  * else if in session is a form of filter-it is Otherwise,
  * if there is a default filters-they are  
  * 
  * @param array $default (stand default filter (option))
  * @return 
  */
 protected function checkFilters($default = array())
 {
     if ($this->filter_fields) {
         $this->filter_form = $this->createForm(new BuilderFormFilterType($this->filter_fields));
         if (count($default)) {
             $this->filter_form->setData($default);
         }
         $method = $this->query instanceof NativeQuery ? 'buildNativeQuery' : 'buildQuery';
         if ($this->get('request')->getMethod() == 'POST') {
             $this->get('session')->remove('_filter_' . $this->get('request')->get('_route'));
             $this->get('session')->remove('_pager_' . $this->get('request')->get('_route'));
             $this->filter_form->bind($this->get('request'));
             $this->get('zk2_admin_panel.query_builder')->{$method}($this->filter_form, $this->query);
             $filterService = $this->get('zk2_admin_panel.form_filter_session');
             $filterService->serialize($this->filter_form->getData(), '_filter_' . $this->get('request')->get('_route'));
         } elseif ($this->get('session')->has('_filter_' . $this->get('request')->get('_route'))) {
             $filterService = $this->get('zk2_admin_panel.form_filter_session');
             $data = $filterService->unserialize('_filter_' . $this->get('request')->get('_route'), $this->em_name);
             $this->filter_form->setData($data);
             $this->get('zk2_admin_panel.query_builder')->{$method}($this->filter_form, $this->query);
         } elseif (count($default)) {
             $this->get('zk2_admin_panel.query_builder')->{$method}($this->filter_form, $this->query);
         }
     }
 }
开发者ID:zk2,项目名称:admin-panel-bundle,代码行数:36,代码来源:AdminPanelController.php

示例5: process

 /**
  * @param UserInterface $user
  *
  * @return bool
  */
 public function process(UserInterface $user)
 {
     $this->form->setData($user);
     if ('POST' == $this->request->getMethod()) {
         $this->form->bind($this->request);
         if ($this->form->isValid()) {
             $this->onSuccess($user);
             return true;
         }
         // Reloads the user to reset its username. This is needed when the
         // username or password have been changed to avoid issues with the
         // security layer.
         $this->userManager->reloadUser($user);
     }
     return false;
 }
开发者ID:Tagarela76,项目名称:table4you,代码行数:21,代码来源:ProfileFormHandler.php

示例6: process

 /**
  * Processes the form with the request
  *
  * @param Form $form
  * @return Message|false the sent message if the form is bound and valid, false otherwise
  */
 public function process(Form $form)
 {
     if ('POST' !== $this->request->getMethod()) {
         return false;
     }
     $form->bind($this->request);
     if ($form->isValid()) {
         return $this->processValidForm($form);
     }
     return false;
 }
开发者ID:gpuck,项目名称:FOSMessageBundle,代码行数:17,代码来源:AbstractMessageFormHandler.php

示例7: handle

 /**
  * @param Form    $form
  * @param Request $request
  * @param array   $options
  *
  * @return bool
  */
 public function handle(Form $form, Request $request, array $options = null)
 {
     if (!$request->isMethod('POST')) {
         return false;
     }
     $form->bind($request->request->get($form->getName()));
     if (!$form->isBound() || !$form->isValid()) {
         return false;
     }
     $this->usermanager->createUser($form->getData()->getUser());
     return true;
 }
开发者ID:nicolas-grekas,项目名称:workshop-symfony3,代码行数:19,代码来源:RegistrationFormHandler.php

示例8: testDataIsInitializedFromBind

 public function testDataIsInitializedFromBind()
 {
     $mock = $this->getMockBuilder('\\stdClass')->setMethods(array('preSetData', 'preBind'))->getMock();
     $mock->expects($this->at(0))->method('preSetData');
     $mock->expects($this->at(1))->method('preBind');
     $config = new FormConfigBuilder('name', null, $this->dispatcher);
     $config->addEventListener(FormEvents::PRE_SET_DATA, array($mock, 'preSetData'));
     $config->addEventListener(FormEvents::PRE_BIND, array($mock, 'preBind'));
     $form = new Form($config);
     // no call to setData() or similar where the object would be
     // initialized otherwise
     $form->bind('foobar');
 }
开发者ID:nfabre,项目名称:symfony,代码行数:13,代码来源:SimpleFormTest.php

示例9: testFalseIsConvertedToNull

 public function testFalseIsConvertedToNull()
 {
     $mock = $this->getMockBuilder('\\stdClass')->setMethods(array('preBind'))->getMock();
     $mock->expects($this->once())->method('preBind')->with($this->callback(function ($event) {
         return null === $event->getData();
     }));
     $config = new FormConfigBuilder('name', null, $this->dispatcher);
     $config->addEventListener(FormEvents::PRE_BIND, array($mock, 'preBind'));
     $form = new Form($config);
     $form->bind(false);
     $this->assertTrue($form->isValid());
     $this->assertNull($form->getData());
 }
开发者ID:NivalM,项目名称:VacantesJannaMotors,代码行数:13,代码来源:SimpleFormTest.php

示例10: process

 /**
  *
  * @access public
  * @return bool
  */
 public function process()
 {
     $this->getForm();
     if ($this->request->getMethod() == 'POST') {
         $this->form->bind($this->request);
         // Validate
         if ($this->form->isValid()) {
             if ($this->getSubmitAction() == 'post') {
                 $formData = $this->form->getData();
                 $this->onSuccess($formData);
                 return true;
             }
         }
     }
     return false;
 }
开发者ID:josephzhao,项目名称:map2uforum,代码行数:21,代码来源:BaseFormHandler.php

示例11: validateForm

 protected function validateForm(Form $form, $request_data)
 {
     $form->bind($request_data);
     if (!$form->isValid()) {
         $msg = $form->getErrors();
         if (sizeOf($msg)) {
             $msg = array_map(function ($message) {
                 return $message->getMessage();
             }, $msg);
             $msg = "\n- " . implode("\n- ", $msg);
         } else {
             $msg = "\n- " . $form->getErrorsAsString();
         }
         $this->get('logger')->err('Erreur formulaire: ' . $msg);
         throw new InvalidArgumentException($msg);
     }
 }
开发者ID:bf13,项目名称:bf13,代码行数:17,代码来源:Controller.php

示例12: process

 /**
  * {@inheritDoc}
  */
 public function process(Request $request, Form $form, UserResponseInterface $userInformation)
 {
     $user = $this->userManager->createUser();
     // Try to get some properties for the initial form when coming from github
     if ('GET' === $request->getMethod()) {
         $user->setUsername($this->getUniqueUsername($userInformation->getNickname()));
         if ($userInformation instanceof AdvancedUserResponseInterface) {
             $user->setEmail($userInformation->getEmail());
         }
     }
     $form->setData($user);
     if ('POST' === $request->getMethod()) {
         $form->bind($request);
         if ($form->isValid()) {
             $randomPassword = $this->tokenGenerator->generateToken();
             $user->setPlainPassword($randomPassword);
             $user->setEnabled(true);
             $apiToken = substr($this->tokenGenerator->generateToken(), 0, 20);
             $user->setApiToken($apiToken);
             return true;
         }
     }
     return false;
 }
开发者ID:enriquesomolinos,项目名称:packagist,代码行数:27,代码来源:OAuthRegistrationFormHandler.php

示例13: filterNate

 /**
  * Takes a form and query builder and returns filtered and paginated entities
  * @param QueryBuilder   $filterBuilder
  * @param Form           $form
  * @param string         $session_key
  * @param int            $limit
  * @param int            $page_number
  *
  * @return mixed
  */
 public function filterNate($filterBuilder, &$form, $session_key, $limit = 5, $page_number = 1)
 {
     $em = $this->container->get('doctrine')->getManager();
     $paginator = $this->container->get('knp_paginator');
     $lexik = $this->container->get('lexik_form_filter.query_builder_updater');
     $session = $this->container->get('session');
     $request = $this->container->get('request');
     if ($request->getMethod() == "POST") {
         // bind values from the request
         $form->bind($request);
         // build the query from the given form object
         $session->set("filternator_{$session_key}", $form->getData());
     } else {
         if ($session->has("filternator_{$session_key}")) {
             $data = $session->get("filternator_{$session_key}");
             $this->manageObjects($data, $em);
             $form->setData($data);
         }
     }
     $lexik->addFilterConditions($form, $filterBuilder);
     $entities = $filterBuilder->getQuery()->getResult();
     $pagination = $paginator->paginate($entities, $request->query->get('page', $page_number), $limit);
     return $pagination;
 }
开发者ID:TMSolution,项目名称:FilterNatorBundle,代码行数:34,代码来源:FilterNatorController.php

示例14: testMultipartFormsWithParentsRequireNoFiles

 public function testMultipartFormsWithParentsRequireNoFiles()
 {
     $form = new Form('author', new Author(), $this->validator);
     $form->add($this->createMultipartMockField('file'));
     $form->setParent($this->createMockField('group'));
     // files are expected to be converted by the parent
     $form->bind(array('file' => 'test.txt'));
 }
开发者ID:rsky,项目名称:symfony,代码行数:8,代码来源:FormTest.php

示例15: testSubformAlwaysInsertsIntoArrays

 public function testSubformAlwaysInsertsIntoArrays()
 {
     $ref1 = new Author();
     $ref2 = new Author();
     $author = array('referenceCopy' => $ref1);
     $form = new Form('author', array('validator' => $this->createMockValidator()));
     $form->setData($author);
     $refForm = new FormTest_FormThatReturns('referenceCopy');
     $refForm->setReturnValue($ref2);
     $form->add($refForm);
     $form->bind($this->createPostRequest(array('author' => array('referenceCopy' => array()))));
     // the new reference was inserted into the array
     $author = $form->getData();
     $this->assertSame($ref2, $author['referenceCopy']);
 }
开发者ID:nickaggarwal,项目名称:sample-symfony2,代码行数:15,代码来源:FormTest.php


注:本文中的Symfony\Component\Form\Form::bind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。