Symfony Form - Erwartet argument des Typs "string oder Symfony\Component\Form\FormTypeInterface", "array" gegeben

Ich habe ein Formular erstellt mit der Lehre. Es funktioniert, wenn ich nicht jede option, wie diese:

$builder
    ->add('name')
    ->add('password', 'password')
    ->add('password_repeat', 'password')
    ->add('email', 'email')
    ->add('save', 'submit')
;

Aber, wenn ich ein array mit Optionen, wie Sie sagt, die docs (http://symfony.com/doc/current/book/forms.html#book-form-creating-form-classes), bekomme ich eine Fehlermeldung, die sagt:

Erwartet argument des Typs "string oder Symfony\Component\Form\FormTypeInterface", "array" gegeben

Dies ist die formtype erstellt von Lehre:

<?php

namespace MainBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class UserType extends AbstractType
{
/**
 * @param FormBuilderInterface $builder
 * @param array $options
 */
public function buildForm(FormBuilderInterface $builder, array $options)
{

    $builder
        ->add('name') //if I put ->add('name', array('label' => 'Your name')) I get the error
        ->add('password', 'password')
        ->add('password_repeat', 'password')
        ->add('email', 'email')
        ->add('save', 'submit')
    ;

}

/**
 * @param OptionsResolverInterface $resolver
 */
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
    $resolver->setDefaults(array(
        'data_class' => 'MainBundle\Entity\User'
    ));
}

/**
 * @return string
 */
public function getName()
{
    return 'mainbundle_user';
}
}

 

InformationsquelleAutor roger.vila | 2015-06-01
Schreibe einen Kommentar