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


PHP Form::getIterator方法代码示例

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


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

示例1: getFormAsArray

 /**
  * @param Form $form
  * @return array
  */
 public static function getFormAsArray(Form $form)
 {
     $formTypesData = array();
     $formTypes = $form->getIterator();
     foreach ($formTypes as $formType) {
         /** @var Form $formType */
         $formTypesData[$formType->getName()] = $formType->getData();
     }
     return $formTypesData;
 }
开发者ID:phatj,项目名称:CrudAbstractDataBundle,代码行数:14,代码来源:FormTools.php

示例2: formEncode

 public function formEncode($entity, Form $form, AbstractType $formType)
 {
     $baseName = $formType->getName();
     $payload = array();
     foreach ($form->getIterator() as $el) {
         if (is_array($entity)) {
             $payload[$baseName . '[' . $el->getName() . ']'] = $entity[$el->getName()];
         }
     }
     return $payload;
 }
开发者ID:ChMat,项目名称:CoreBundle,代码行数:11,代码来源:ApiManager.php

示例3: serialize

 private function serialize(\Symfony\Component\Form\Form $form)
 {
     $local_errors = array();
     foreach ($form->getIterator() as $key => $child) {
         foreach ($child->getErrors() as $error) {
             $local_errors[$key] = $error->getMessage();
         }
         if (count($child->getIterator()) > 0) {
             $local_errors[$key] = $this->serialize($child);
         }
     }
     return $local_errors;
 }
开发者ID:Pulpmedia,项目名称:PulpmediaNgHttpBundle,代码行数:13,代码来源:FormErrorsSerializer.php

示例4: bindForm

 public function bindForm(Form $form)
 {
     $fields = $form->getIterator();
     /** @var \Symfony\Component\Form\Form $field */
     foreach ($fields as $field) {
         $functionName = sprintf("set%s", Container::camelize($field->getName()));
         if (method_exists($this, $functionName)) {
             $this->{$functionName}($field->getData());
         } else {
             $this->{$field->getName()} = $field->getData();
         }
     }
 }
开发者ID:alex63530,项目名称:thelia,代码行数:13,代码来源:ActionEvent.php

示例5: getRecursiveReadableErrors

 /**
  * Returns a string representation of all form errors (including children errors).
  *
  * This method should only be used in ajax calls.
  *
  * @param Form $form         The form to parse
  * @param bool $withChildren Do we parse the embedded forms
  *
  * @return string A string representation of all errors
  */
 public function getRecursiveReadableErrors($form, $withChildren = true, $translationDomain = null, $level = 0)
 {
     $errors = '';
     $translationDomain = $translationDomain ? $translationDomain : $form->getConfig()->getOption('translation_domain');
     //the errors of the fields
     foreach ($form->getErrors() as $error) {
         //the view contains the label identifier
         $view = $form->createView();
         $labelId = $view->vars['label'];
         //get the translated label
         if ($labelId !== null) {
             $label = $this->translator->trans($labelId, [], $translationDomain) . ' : ';
         } else {
             $label = '';
         }
         //in case of dev mode, we display the item that is a problem
         //getCause cames in Symfony 2.5 version, this is just a fallback to avoid BC with previous versions
         if ($this->debug && method_exists($error, 'getCause')) {
             $cause = $error->getCause();
             if ($cause !== null) {
                 $causePropertyPath = $cause->getPropertyPath();
                 $errors .= ' ' . $causePropertyPath;
             }
         }
         //add the error
         $errors .= $label . $this->translator->trans($error->getMessage(), [], $translationDomain) . "\n";
     }
     //do we parse the children
     if ($withChildren) {
         //we parse the children
         foreach ($form->getIterator() as $child) {
             $level++;
             if ($err = $this->getRecursiveReadableErrors($child, $withChildren, $translationDomain, $level)) {
                 $errors .= $err;
             }
         }
     }
     return $errors;
 }
开发者ID:victoire,项目名称:victoire,代码行数:49,代码来源:FormErrorHelper.php

示例6: getErrors

 /**
  * Get all form errors
  * @param Form $form
  * @return array
  */
 private function getErrors(Form $form)
 {
     $errors = array();
     $children = $form->getIterator();
     /** @var Form $child */
     foreach ($children as $child) {
         if (!$child->isValid()) {
             $errors[$form->getName() . '[' . $child->getName() . ']'] = $this->getErrors($child);
         }
     }
     foreach ($form->getErrors() as $key => $error) {
         $errors[] = $error->getMessage();
     }
     return $errors;
 }
开发者ID:steve-todorov,项目名称:symfony2-angular-forms,代码行数:20,代码来源:DemoController.php

示例7: getFormErrors

 /**
  * Dado un formulario se devuelven sus errores parseados
  * @param Form $form
  * @param bool $deep option for Form getErrors method
  * @param bool $flatten option for Form getErrors method
  * @return array
  */
 public function getFormErrors(Form $form, $deep = false, $flatten = true)
 {
     // Se parsean los errores que existan en el formulario para devolverlos en el reponse
     $errors = array();
     //Se parsean los posibles errores generales del formulario(incluyendo los asserts a nivel de entidad)
     foreach ($form->getErrors($deep, $flatten) as $key => $error) {
         if ($form->isRoot()) {
             $errors['form'][] = $error->getMessage();
         } else {
             $errors[] = $error->getMessage();
         }
     }
     $childs = $form->getIterator();
     //Se parsean los posibles errores de cada campo del formulario
     /** @var Form $child */
     foreach ($childs as $child) {
         $fieldErrors = $child->getErrors();
         while ($fieldErrors->current() != null) {
             $errors[$child->getName()][] = $fieldErrors->current()->getMessage();
             $fieldErrors->next();
         }
     }
     return $errors;
 }
开发者ID:sopinet,项目名称:apihelper-bundle,代码行数:31,代码来源:ApiHelper.php


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