本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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();
}
}
}
示例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;
}
示例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;
}
示例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;
}