本文整理汇总了PHP中Symfony\Component\Form\Form::getChildren方法的典型用法代码示例。如果您正苦于以下问题:PHP Form::getChildren方法的具体用法?PHP Form::getChildren怎么用?PHP Form::getChildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\Form
的用法示例。
在下文中一共展示了Form::getChildren方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAllErrors
public static function getAllErrors(Form $form, $parent_prefix = '')
{
$id = $parent_prefix . ($parent_prefix ? '_' : '') . $form->getName();
$errors = array($id . '_errors' => array());
foreach ($form->getErrors() as $error) {
$errors[$id . '_errors'][] = array('error' => self::formatErrors($error));
}
if (!count($errors[$id . '_errors'])) {
unset($errors[$id . '_errors']);
}
foreach ($form->getChildren() as $child) {
if ($_errors = self::getAllErrors($child, $id)) {
$errors = array_merge($errors, $_errors);
}
}
if (count($errors)) {
return $errors;
} else {
return false;
}
}
示例2: getErrorMessages
private function getErrorMessages(\Symfony\Component\Form\Form $form)
{
$errors = array();
foreach ($form->getErrors() as $key => $error) {
$template = $error->getMessageTemplate();
$parameters = $error->getMessageParameters();
foreach ($parameters as $var => $value) {
$template = str_replace($var, $value, $template);
}
$errors[$key] = $template;
}
if ($form->hasChildren()) {
foreach ($form->getChildren() as $child) {
if (!$child->isValid()) {
$errors[$child->getName()] = $this->getErrorMessages($child);
}
}
}
return $errors;
}
示例3: convertFormToArray
private function convertFormToArray(GenericSerializationVisitor $visitor, Form $data)
{
$isRoot = null === $visitor->getRoot();
$form = $errors = array();
foreach ($data->getErrors() as $error) {
$errors[] = $this->getErrorMessage($error);
}
if ($errors) {
$form['errors'] = $errors;
}
$children = array();
foreach ($data->getChildren() as $child) {
$children[$child->getName()] = $this->convertFormToArray($visitor, $child);
}
if ($children) {
$form['children'] = $children;
}
if ($isRoot) {
$visitor->setRoot($form);
}
return $form;
}