php - Symfony Form - Expected argument of type "string or Symfony\Component\Form\FormTypeInterface", "array" given -
i have created form doctrine. works if not pass option, this:
$builder ->add('name') ->add('password', 'password') ->add('password_repeat', 'password') ->add('email', 'email') ->add('save', 'submit') ;
but, if add array options says docs (http://symfony.com/doc/current/book/forms.html#book-form-creating-form-classes), error says:
expected argument of type "string or symfony\component\form\formtypeinterface", "array" given
this formtype created doctrine:
<?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 put ->add('name', array('label' => 'your name')) 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'; } }
you must specify type of field before adding options
$builder->add('name', 'text', array('label' => 'your name'))
Comments
Post a Comment