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


PHP Form::setData方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: setData

 public function setData($collection)
 {
     if (!is_array($collection) && !$collection instanceof \Traversable) {
         throw new UnexpectedTypeException($collection, 'array or \\Traversable');
     }
     foreach ($this as $name => $field) {
         if (!$this->getOption('modifiable') || '$$key$$' != $name) {
             $this->remove($name);
         }
     }
     foreach ($collection as $name => $value) {
         $this->add($this->newField($name, $name));
     }
     parent::setData($collection);
 }
开发者ID:nickaggarwal,项目名称:sample-symfony2,代码行数:15,代码来源:CollectionField.php

示例5: 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()));
         $user->setEmail($userInformation->getEmail());
     }
     $form->setData($user);
     if ('POST' === $request->getMethod()) {
         $form->handleRequest($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:yjqg6666,项目名称:packagist,代码行数:25,代码来源:OAuthRegistrationFormHandler.php

示例6: 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

示例7: getForm

    public function getForm()
    {
        $instance = new Form(
            $this->getName(),
            $this->buildDispatcher(),
            $this->getTypes(),
            $this->getClientTransformers(),
            $this->getNormTransformers(),
            $this->getDataMapper(),
            $this->getValidators(),
            $this->getRequired(),
            $this->getReadOnly(),
            $this->getErrorBubbling(),
            $this->getEmptyData(),
            $this->getAttributes()
        );

        foreach ($this->buildChildren() as $child) {
            $instance->add($child);
        }

        if ($this->getData()) {
            $instance->setData($this->getData());
        }

        return $instance;
    }
开发者ID:nacef,项目名称:symfony,代码行数:27,代码来源:FormBuilder.php

示例8: 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

示例9: testSetDataCannotInvokeItself

 /**
  * @expectedException \Symfony\Component\Form\Exception\RuntimeException
  */
 public function testSetDataCannotInvokeItself()
 {
     // Cycle detection to prevent endless loops
     $config = new FormConfigBuilder('name', 'stdClass', $this->dispatcher);
     $config->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
         $event->getForm()->setData('bar');
     });
     $form = new Form($config);
     $form->setData('foo');
 }
开发者ID:yceruto,项目名称:symfony,代码行数:13,代码来源:SimpleFormTest.php

示例10: setData

 /**
  * {@inheritDoc}
  */
 public function setData($data)
 {
     if ($this->mode === self::FORM) {
         parent::setData($data);
     } else {
         Field::setData($data);
     }
 }
开发者ID:rooster,项目名称:symfony,代码行数:11,代码来源:HybridField.php

示例11: testClientDataMustBeObjectIfDataClassIsSet

 /**
  * @expectedException Symfony\Component\Form\Exception\FormException
  */
 public function testClientDataMustBeObjectIfDataClassIsSet()
 {
     $config = new FormConfig('name', 'stdClass', $this->dispatcher);
     $config->addViewTransformer(new FixedDataTransformer(array('' => '', 'foo' => array('bar' => 'baz'))));
     $form = new Form($config);
     $form->setData('foo');
 }
开发者ID:laubosslink,项目名称:lab,代码行数:10,代码来源:FormTest.php

示例12: testUpdatePropertyIsNotIgnoredIfFormHasNoObject

 public function testUpdatePropertyIsNotIgnoredIfFormHasNoObject()
 {
     $author = new Author();
     $child = new Author();
     $form = new Form('child');
     $form->setData($child);
     $form->updateProperty($author);
     // $author->child was set
     $this->assertSame($child, $author->child);
 }
开发者ID:spf13,项目名称:symfony,代码行数:10,代码来源:FormTest.php


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