2

I have a problem with a simple form. I have a class called JurisdictionUser() and my class form is JurisdictionUserNewType(). If I put the next code, its work fine:

$jurisdiction_user = new JurisdictionUser();
$form = $this->createFormBuilder($jurisdiction_user)
        ->add('name', 'text')
        ->add('email', 'text', array('required' => false))
        ->add('save', 'submit')
        ->getForm();

but, if I put the next code:

$jurisdiction_user = new JurisdictionUser();
$form = $this->createFormBuilder(new JurisdictionUserNewType(), $jurisdiction_user);

It give me the next error:

ContextErrorException: Catchable Fatal Error: Argument 2 passed to Symfony\Bundle\FrameworkBundle\Controller\Controller::createFormBuilder() must be of the type array, object given, called in /home/sierra/dev_env/iyc-open010/src/Radmas/BackofficeAdminBundle/Controller/UserAdminController.php on line 119 and defined in /home/sierra/dev_env/iyc-open010/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php line 175

I need help xD. My class JurisdictionUserNewType().

    <?php
/**
 * Created by PhpStorm.
 * User: diego
 * Date: 15/01/14
 * Time: 16:21
 */

namespace Radmas\BackofficeAdminBundle\Form\Type;
use Radmas\BackofficeAdminBundle\Form\Transformer\CapitalToSmallLetterTransformer;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class JurisdictionUserNewType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $transformer = new CapitalToSmallLetterTransformer();

        $builder
            ->add('name', 'text');

        $builder->add(
            $builder->create('email', 'text', array('required' => false))
                ->addModelTransformer($transformer)
        );
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
           'data_class' => 'Radmas\Open010Bundle\Document\JurisdictionUser'
        ));
    }

    public function getName()
    {
        return 'jurisdictionUserNew';
    }
}

1 Answer 1

3

You should use

$this->createForm(new JurisdictionUserNewType(), $jurisdiction_user)

in controller, instead of createFormBuilder.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.