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


PHP Form::getData方法代码示例

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


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

示例1: validate

 public function validate($data)
 {
     $this->form->setData($data);
     $isValid = $this->form->isValid();
     $normalized = $this->form->getData();
     unset($normalized['ViewReportControl']);
     $validated = new \SSRS\Form\ValidateResult();
     $validated->isValid = $isValid;
     $validated->parameters = $normalized;
     return $validated;
 }
开发者ID:caseypage,项目名称:php-ssrs-1,代码行数:11,代码来源:ZendFramework2.php

示例2: add

 /**
  * @param \Zend\Form\Form $form
  * @param $data
  * @return Entity\Comment|null
  * @throws \Exception
  */
 public function add(\Zend\Form\Form $form, $data)
 {
     $serviceLocator = $this->getServiceLocator();
     $entityManager = $serviceLocator->get('Doctrine\\ORM\\EntityManager');
     $entityType = $entityManager->getRepository('\\Comment\\Entity\\EntityType')->findOneByAlias($data['alias']);
     if (!$entityType) {
         throw new EntityNotFoundException();
     }
     $form->setData($data);
     if ($form->isValid()) {
         if ($entityType->getIsEnabled()) {
             $data = $form->getData();
             $comment = new Entity\Comment();
             $comment->setEntityType($entityType);
             $user = $serviceLocator->get('Zend\\Authentication\\AuthenticationService')->getIdentity()->getUser();
             $comment->setUser($user);
             $comment->setComment($data['comment']);
             $entityManager->getConnection()->beginTransaction();
             try {
                 $hydrator = new DoctrineHydrator($entityManager);
                 $hydrator->hydrate($data, $comment);
                 $entityType->getComments()->add($comment);
                 $entityManager->persist($comment);
                 $entityManager->persist($entityType);
                 $entityManager->flush();
                 $entityManager->getConnection()->commit();
                 return $comment;
             } catch (\Exception $e) {
                 $entityManager->getConnection()->rollback();
                 throw $e;
             }
         }
     }
     return null;
 }
开发者ID:zfury,项目名称:cmf,代码行数:41,代码来源:Comment.php

示例3: testExtractDataHydratorStrategy

    public function testExtractDataHydratorStrategy()
    {
        $this->populateHydratorStrategyForm();

        $hydrator = new Hydrator\ObjectProperty();
        $hydrator->addStrategy('entities', new TestAsset\HydratorStrategy());
        $this->form->setHydrator($hydrator);

        $model = new TestAsset\HydratorStrategyEntityA();
        $this->form->bind($model);

        $validSet = array(
            'entities' => array(
                111,
                333
            ),
        );

        $this->form->setData($validSet);
        $this->form->isValid();

        $data = $this->form->getData(Form::VALUES_AS_ARRAY);
        $this->assertEquals($validSet, $data);

        $entities = $model->getEntities();
        $this->assertCount(2, $entities);

        $this->assertEquals(111, $entities[0]->getField1());
        $this->assertEquals(333, $entities[1]->getField1());

        $this->assertEquals('AAA', $entities[0]->getField2());
        $this->assertEquals('CCC', $entities[1]->getField2());
    }
开发者ID:benivaldo,项目名称:zf2-na-pratica,代码行数:33,代码来源:FormTest.php

示例4: updateAction

 public function updateAction()
 {
     if (!($seo = $this->loadObject($this->seoService, "Seo record doesn't exist."))) {
         return $this->redirect()->toRoute('seo', array('action' => 'list'));
     }
     $this->seoForm->bind($seo);
     if ($this->request->isPost()) {
         $this->seoForm->setData($this->request->getPost());
         if ($this->seoForm->isValid()) {
             $this->seoService->update($this->seoForm->getData());
             $this->flashMessenger()->addSuccessMessage(sprintf('Seo "%s" has been successfully updated.', $seo->getId()));
             return $this->redirect()->toRoute('seo', array('action' => 'list'));
         }
     }
     $view = new ViewModel(array('id' => $seo->getId(), 'form' => $this->seoForm));
     $view->setTerminal(true);
     return $view;
 }
开发者ID:nsenkevich,项目名称:seo,代码行数:18,代码来源:SeoController.php

示例5: createFromForm

 /**
  * createFromForm
  *
  * @param Form $form
  * @return CdliTwoStageSignup\Model\EmailVerification
  */
 public function createFromForm(Form $form)
 {
     $form->bind(new Model());
     if (!$form->isValid()) {
         return false;
     }
     $model = $form->getData();
     $model->generateRequestKey();
     $this->getEventManager()->trigger(__FUNCTION__, $this, array('record' => $model, 'form' => $form));
     $this->getEmailVerificationMapper()->insert($model);
     return $model;
 }
开发者ID:cdli,项目名称:cdlitwostagesignup,代码行数:18,代码来源:EmailVerification.php

示例6: persist

 public function persist(Form $form)
 {
     $data = $form->getData();
     foreach ($data['products'] as $productId => $options) {
         foreach ($options as $optionId => $choiceId) {
             $row = array('product_id' => $productId, 'option_id' => $optionId, 'choice_id' => $choiceId);
             $this->getEntityMapper()->persist($row);
         }
     }
     $builder = $this->newBuilderForProduct($data['product_id'], $data['parent_product_id']);
     return $builder;
 }
开发者ID:nclundsten,项目名称:SpeckCatalog,代码行数:12,代码来源:Builder.php

示例7: getData

 /**
  * @author VanCK
  * @see \Zend\Form\Form::getData()
  */
 public function getData($flag = FormInterface::VALUES_NORMALIZED)
 {
     $data = parent::getData($flag);
     // populate default values
     foreach ($this->getElements() as $element) {
         /* @var $element \Zend\Form\Element */
         if ((!count($this->data) || !array_key_exists($element->getName(), $this->data)) && $element->getValue()) {
             $data[$element->getName()] = $element->getValue();
         }
     }
     return $data;
 }
开发者ID:NguyenQuiDuong,项目名称:Funixtest,代码行数:16,代码来源:FormBase.php

示例8: getData

 public function getData($flag = FormInterface::VALUES_NORMALIZED)
 {
     $data = parent::getData($flag);
     if (false === $this->isNew()) {
         foreach ($this->getOriginalFields() as $field) {
             $key = 'original_' . $field;
             if (array_key_exists($key, $data)) {
                 unset($data[$key]);
             }
         }
     }
     return parent::getData($flag);
 }
开发者ID:pixlr,项目名称:SpeckCatalog,代码行数:13,代码来源:AbstractForm.php

示例9: saveAction

 public function saveAction(Request $request, Create $createService, Form $form, View $view, Redirect $redirect)
 {
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $createService->create($form->getData());
             return $redirect->toRoute('admin-translate-words');
         }
     }
     $view->setForm($form);
     $view->setTemplate('translate/admin/word/edit');
     return $view;
 }
开发者ID:sebaks,项目名称:Translate,代码行数:13,代码来源:WordController.php

示例10: getPreparedFormData

 protected function getPreparedFormData(Form $form)
 {
     $formData = $form->getData();
     foreach ($form->getElements() as $element) {
         if ($element instanceof File) {
             if ($formData[$element->getName()]['size'] == 0) {
                 unset($formData[$element->getName()]);
             } else {
                 $formData[$element->getName()] = $formData[$element->getName()]['tmp_name'];
             }
         }
     }
     unset($formData['save']);
     return $formData;
 }
开发者ID:zend-bricks,项目名称:bricks-user,代码行数:15,代码来源:ProfileController.php

示例11: write

 /**
  * {@inheritdoc}
  *
  * @param \Dms\Document\Document $document
  *
  * @see \Dms\Storage\StorageInterface::write()
  */
 public function write(\Dms\Document\Document $document)
 {
     $ret = null;
     $name = $document->getId();
     $nameMod = substr($name, 4);
     $f = substr($name, 0, 2) . '/' . substr($name, 2, 2) . '/';
     $path = $this->getBasePath() . $f;
     if (!is_dir($path)) {
         mkdir($path, 0777, true);
     }
     $p = $path . $nameMod . '.dat';
     if ($document->getSupport() === Document::SUPPORT_FILE_MULTI_PART_STR) {
         $fileInput = new FileInput(key($document->getDatas()));
         $fileInput->getFilterChain()->attachByName('filerenameupload', ['target' => $p]);
         $inputFilter = new InputFilter();
         $inputFilter->add($fileInput);
         $form = new Form();
         $form->setInputFilter($inputFilter);
         $form->setData($document->getDatas());
         if ($form->isValid()) {
             $form->getData();
         }
     } else {
         $fp = fopen($p, 'w');
         fwrite($fp, $document->getDatas());
         $document->setWeight(strlen($document->getDatas()));
         fclose($fp);
     }
     $conf_storage = $this->options->getStorage();
     if (isset($conf_storage['name']) && $conf_storage['name'] === 's3') {
         print_r($_FILES);
         $this->s3Client->copyObject(['Bucket' => $conf_storage['bucket'], 'Key' => $f . $nameMod . '.dat', 'CopySource' => $conf_storage['bucket'] . '/' . $f . $nameMod . '.dat', 'ContentType' => $document->getType(), 'ContentDisposition' => sprintf('filename=%s', null === $document->getName() ? substr($file, -1 * strlen($document->getFormat())) === $document->getFormat() ? $file : $file . '.' . $document->getFormat() : $document->getName()), 'MetadataDirective' => 'REPLACE']);
     }
     $document->setSupport(Document::SUPPORT_FILE_STR);
     $this->getEventManager()->trigger(__FUNCTION__, $this, array('path' => $path, 'short_name' => $nameMod, 'all_path' => $path . $nameMod . '.dat', 'support' => $document->getSupport(), 'name' => $name));
     $serialize = serialize($document);
     $fp = fopen($path . $nameMod . '.inf', 'w');
     $ret += fwrite($fp, $serialize);
     fclose($fp);
     $this->getEventManager()->trigger(__FUNCTION__, $this, array('path' => $path, 'short_name' => $nameMod, 'all_path' => $path . $nameMod . 'inf', 'support' => $document->getSupport(), 'name' => $name));
     return $ret;
 }
开发者ID:buse974,项目名称:dms,代码行数:49,代码来源:Storage.php

示例12: formAction

 public function formAction()
 {
     // Build a name element.
     $name = new Element('name');
     $name->setLabel('Your name');
     $name->setAttributes(array('type' => 'text'));
     // Build a submit button element.
     $send = new Element('send');
     $send->setLabel('Send');
     $send->setAttributes(array('type' => 'submit', 'value' => 'Send'));
     // Build a checkbox element.
     $check = new Checkbox('check');
     $check->setLabel('Checkbox example');
     // Build a multi-checkbox element.
     $multicheck = new MultiCheckbox('multicheck');
     $multicheck->setLabel('Multi checkbox example');
     $multicheck->setOptions(array('value_options' => array('One' => 'one', 'Two' => 'two')));
     // Assemble the form.
     $form = new Form('contact');
     $form->add($name);
     $form->add($check);
     $form->add($multicheck);
     $form->add($send);
     // Get the request if any.
     $request = $this->getRequest();
     $data = $request->getPost();
     $form->setData($data);
     // Validate the form
     if ($form->isValid()) {
         $validatedData = $form->getData();
         $success = 'Form submit was successful';
     } else {
         $success = 'Form submit failed';
         $messages = $form->getMessages();
     }
     // Set the method attribute for the form
     $form->setAttribute('method', 'post');
     return new ViewModel(array('form' => $form, 'success' => $success, 'messages' => $messages, 'data' => $data));
 }
开发者ID:Tony133,项目名称:zf-web,代码行数:39,代码来源:IndexController.php

示例13: create

 /**
  * @param Form $form
  * @param array $data
  * @return UserInterface|null
  */
 public function create(Form $form, array $data)
 {
     $zfcUserOptions = $this->getZfcUserOptions();
     $user = $form->getData();
     $argv = array();
     if ($this->getOptions()->getCreateUserAutoPassword()) {
         $argv['password'] = $this->generatePassword();
     } else {
         $argv['password'] = $user->getPassword();
     }
     $bcrypt = new Bcrypt();
     $bcrypt->setCost($zfcUserOptions->getPasswordCost());
     $user->setPassword($bcrypt->create($argv['password']));
     foreach ($this->getOptions()->getCreateFormElements() as $element) {
         call_user_func(array($user, $this->getAccessorName($element)), $data[$element]);
     }
     $argv += array('user' => $user, 'form' => $form, 'data' => $data);
     $this->getEventManager()->trigger(__FUNCTION__, $this, $argv);
     $this->getUserMapper()->insert($user);
     $this->getEventManager()->trigger(__FUNCTION__ . '.post', $this, $argv);
     return $user;
 }
开发者ID:rahuldroy,项目名称:ZfcUserAdmin,代码行数:27,代码来源:User.php

示例14: testElementInAFieldsetForSomeModel

 public function testElementInAFieldsetForSomeModel()
 {
     $element = $this->getMoneyFieldset();
     $element->init();
     $fieldset = new Fieldset('hasMoneyElementFieldset');
     $fieldset->add($element, ['name' => 'price']);
     $fieldset->setHydrator(new ClassMethods());
     $fieldset->setUseAsBaseFieldset(true);
     $form = new Form();
     $form->add($fieldset);
     // todo: can't load this
     $form->bind(new HasMoneyPropertyModel());
     $data = ['hasMoneyElementFieldset' => ['price' => ['amount' => '500.25', 'currency' => 'BRL']]];
     $form->setData($data);
     $this->assertTrue($form->isValid());
     $amountValue = $form->get('hasMoneyElementFieldset')->get('price')->get('amount')->getValue();
     $currencyValue = $form->get('hasMoneyElementFieldset')->get('price')->get('currency')->getValue();
     $object = $form->getData();
     $this->assertSame('500.25', $amountValue);
     $this->assertSame('BRL', $currencyValue);
     $this->assertInstanceOf(Money::class, $object->getPrice());
     $this->assertSame(50025, $object->getPrice()->getAmount());
     $this->assertSame('BRL', $object->getPrice()->getCurrency()->getName());
 }
开发者ID:zfbrasil,项目名称:doctrine-money-module,代码行数:24,代码来源:FormIntegrationTest.php

示例15: processNodeForm

 /**
  * Verarbeitet das Formular zum Erstellen eines Nodes.
  *
  * @param \Zend\Form\Form $form            
  * @return \Zend\Http\PhpEnvironment\Response|boolean
  */
 public function processNodeForm(\Zend\Form\Form $form)
 {
     $prg = $this->getServiceLocator()->get('controllerpluginmanager')->get('prg')->__invoke();
     if ($prg instanceof \Zend\Http\PhpEnvironment\Response) {
         return $prg;
     } elseif (true === is_array($prg)) {
         $form->setData($prg);
         if (true == $form->isValid()) {
             $node = $form->getData();
             $this->saveNode($node);
             return true;
         }
     }
     return false;
 }
开发者ID:alexsawallich,项目名称:node,代码行数:21,代码来源:NodeService.php


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