本文整理匯總了PHP中Symfony\Component\Form\Form::count方法的典型用法代碼示例。如果您正苦於以下問題:PHP Form::count方法的具體用法?PHP Form::count怎麽用?PHP Form::count使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\Form\Form
的用法示例。
在下文中一共展示了Form::count方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getFormErrorMessages
public function getFormErrorMessages(\Symfony\Component\Form\Form $form)
{
$errors = array();
$formErrors = iterator_to_array($form->getErrors(false, true));
foreach ($formErrors 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->count()) {
foreach ($form as $child) {
if (!$child->isValid()) {
$errors[$child->getName()] = $this->getFormErrorMessages($child);
}
}
}
return $errors;
}
示例2: getFormErrors
public function getFormErrors(\Symfony\Component\Form\Form $form)
{
$errors = array();
if ($form->count() > 0) {
foreach ($form->all() as $child) {
/**
* @var \Symfony\Component\Form\Form $child
*/
if (!$child->isValid()) {
$errors[$child->getName()] = $this->getFormErrors($child);
}
}
} else {
/**
* @var \Symfony\Component\Form\FormError $error
*/
foreach ($form->getErrors() as $key => $error) {
$errors[] = $error->getMessage();
}
}
return $errors;
}
示例3: getErrorMessages
private function getErrorMessages(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->count()) {
foreach ($form as $child) {
if (!$child->isValid()) {
$errors[$child->getName()] = $this->getErrorMessages($child);
}
}
}
return $errors;
}
示例4: getErrorMessages
/**
* Collects error messages from a symfony form object
*
* @param \Symfony\Component\Form\Form $form
* @return array An array containing form error messages
*/
public static function getErrorMessages(\Symfony\Component\Form\Form $form, $i = null)
{
$errors = array();
if (null === $i) {
$i = 0;
}
foreach ($form->getErrors() as $error) {
$template = $error->getMessageTemplate();
$parameters = $error->getMessageParameters();
foreach ($parameters as $var => $value) {
$template = str_replace($var, $value, $template);
}
$errors[$i] = $template;
$i++;
}
if ($form->count()) {
foreach ($form as $child) {
if (!$child->isValid()) {
$errors = array_merge($errors, self::getErrorMessages($child, $i));
}
}
}
return $errors;
}
示例5: getErrorMessages
/**
* Generate a simpler validation error structure.
*
* @param \Symfony\Component\Form\Form $form
* @return type
*/
private function getErrorMessages(\Symfony\Component\Form\Form $form)
{
$errors = array();
foreach ($form->getErrors() as $key => $error) {
$errors[$key] = $error->getMessage();
}
if ($form->count()) {
foreach ($form->all() as $child) {
if (!$child->isValid()) {
$errors[$child->getName()] = $this->getErrorMessages($child);
}
}
}
return $errors;
}