4

I have the following route:

blog_show:
    path:      /test/123
    defaults:  { _controller: TotalcanBravofillBundle:Test:test }

And this controller:

    public function testAction()
    {
        $form = $this->createForm(new TestType(), new Test());

        return $this->render('TotalcanBravofillBundle:Test:test.html.twig', array(
            'form' => $form->createView(),
       ));
    }

I have this entity:

...
class Test
{
/**
     * @var string
     *
     * @ORM\Column(name="txt", type="text")
     */
    private $txt;
...

And this form:

public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('int')
            ->add('txt')
        ;
    }

I have this view:

{% extends "TotalcanBravofillBundle::index.html.twig" %}

{% block content %}
    {{ form_errors(form) }}
    {{ form_widget(form) }}
{% endblock %}

And it doesn't work; I get the following error:

Could not load type "text"
500 Internal Server Error - InvalidArgumentException

What am I doing wrong?

Stack trace:

at FormRegistry ->getType ('text') 
in /var/www/total1/data/bravofill/vendor/symfony/symfony/src/Symfony/Component/Form/FormFactory.php at line 82   + 
at FormFactory ->createNamedBuilder ('txt', 'text', null, array('required' => true)) 
in /var/www/total1/data/bravofill/vendor/symfony/symfony/src/Symfony/Component/Form/FormFactory.php at line 126   + 
at FormFactory ->createBuilderForProperty ('Totalcan\BravofillBundle\Entity\Test', 'txt', null, array()) 
in /var/www/total1/data/bravofill/vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php at line 109   + 
at FormBuilder ->create ('txt', null, array()) 
in /var/www/total1/data/bravofill/vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php at line 270   + 
at FormBuilder ->resolveChildren () 
in /var/www/total1/data/bravofill/vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php at line 218   + 
at FormBuilder ->getForm () 
in /var/www/total1/data/bravofill/vendor/symfony/symfony/src/Symfony/Component/Form/FormFactory.php at line 39   + 
at FormFactory ->create (object(TestType), object(Test), array()) 
in /var/www/total1/data/bravofill/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php at line 163   + 
at Controller ->createForm (object(TestType), object(Test)) 
in /var/www/total1/data/bravofill/src/Totalcan/BravofillBundle/Controller/TestController.php at line 14   + 
at TestController ->testAction () 
at call_user_func_array (array(object(TestController), 'testAction'), array()) 
in kernel.root_dir/bootstrap.php.cache at line 2774   + 
at HttpKernel ->handleRaw (object(Request), '1') 
in kernel.root_dir/bootstrap.php.cache at line 2748   + 
at HttpKernel ->handle (object(Request), '1', true) 
in kernel.root_dir/bootstrap.php.cache at line 2878   + 
at ContainerAwareHttpKernel ->handle (object(Request), '1', true) 
in kernel.root_dir/bootstrap.php.cache at line 2179   + 
at Kernel ->handle (object(Request)) 
in /var/www/total1/data/bravofill/web/app_dev.php at line 28   + 

Debug:

form.type.birthday   birthday   container Symfony\Component\Form\Extension\Core\Type\BirthdayType
form.type.button     button     container Symfony\Component\Form\Extension\Core\Type\ButtonType
form.type.checkbox   checkbox   container Symfony\Component\Form\Extension\Core\Type\CheckboxType
form.type.choice     choice     container Symfony\Component\Form\Extension\Core\Type\ChoiceType
form.type.collection collection container Symfony\Component\Form\Extension\Core\Type\CollectionType
form.type.country    country    container Symfony\Component\Form\Extension\Core\Type\CountryType
form.type.currency   currency   container Symfony\Component\Form\Extension\Core\Type\CurrencyType
form.type.date       date       container Symfony\Component\Form\Extension\Core\Type\DateType
form.type.datetime   datetime   container Symfony\Component\Form\Extension\Core\Type\DateTimeType
form.type.email      email      container Symfony\Component\Form\Extension\Core\Type\EmailType
form.type.entity     entity     container Symfony\Bridge\Doctrine\Form\Type\EntityType
form.type.file       file       container Symfony\Component\Form\Extension\Core\Type\FileType
form.type.form       form       container Symfony\Component\Form\Extension\Core\Type\FormType
form.type.hidden     hidden     container Symfony\Component\Form\Extension\Core\Type\HiddenType
form.type.integer    integer    container Symfony\Component\Form\Extension\Core\Type\IntegerType
form.type.language   language   container Symfony\Component\Form\Extension\Core\Type\LanguageType
form.type.locale     locale     container Symfony\Component\Form\Extension\Core\Type\LocaleType
form.type.money      money      container Symfony\Component\Form\Extension\Core\Type\MoneyType
form.type.number     number     container Symfony\Component\Form\Extension\Core\Type\NumberType
form.type.password   password   container Symfony\Component\Form\Extension\Core\Type\PasswordType
form.type.percent    percent    container Symfony\Component\Form\Extension\Core\Type\PercentType
form.type.radio      radio      container Symfony\Component\Form\Extension\Core\Type\RadioType
form.type.repeated   repeated   container Symfony\Component\Form\Extension\Core\Type\RepeatedType
form.type.reset      reset      container Symfony\Component\Form\Extension\Core\Type\ResetType
form.type.search     search     container Symfony\Component\Form\Extension\Core\Type\SearchType
form.type.submit     submit     container Symfony\Component\Form\Extension\Core\Type\SubmitType
form.type.textarea   textarea   container Symfony\Component\Form\Extension\Core\Type\TextareaType
form.type.time       time       container Symfony\Component\Form\Extension\Core\Type\TimeType
form.type.timezone   timezone   container Symfony\Component\Form\Extension\Core\Type\TimezoneType
form.type.url        url        container Symfony\Component\Form\Extension\Core\Type\UrlType
9
  • 1
    text is a string without maximum length - i doubt this is the problem here. Commented Jul 19, 2013 at 14:07
  • integer work, string and text didnt. It is trouble with form, when i hardcode field type: ->add('txt', 'integer') it work! Commented Jul 19, 2013 at 14:11
  • 1
    could you please provide the output of app/console container:debug --show-private --tag=form.type ? Commented Jul 19, 2013 at 14:16
  • 1
    I already asked you to test with hardcoded ->add("txt","textarea") before but you said this throws the same exception ... while clearly form.type.text doesn't seem to exist ... textarea should work - please re-verify ! Commented Jul 19, 2013 at 14:45
  • 1
    Just for who wonders, nowadays the command from @NicolaiFröhlich is with debug:container rather than container:debug. Commented Oct 22, 2019 at 12:40

2 Answers 2

5

when building your form you are not declaring any mappings of your entity to fields: http://symfony.com/doc/current/book/forms.html#building-the-form

this should work:

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('int', 'int')
        ->add('txt', 'text')
    ;
}

I'd highly advise against renaming Symfony2 field mappings as in the other answer - your code will break everytime you upgrade Symfony.

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

Comments

3

I got it!

services:
  form.type.anchor:
          class: Totalcan\BravofillBundle\Form\AnchorType
          arguments: ["@security.context"]
  form.type.user:
          class: Totalcan\BravofillBundle\Form\UserType
          arguments: ["@security.context"]

            vvvv---- here, need rename
  form.type.text:
          class: Totalcan\BravofillBundle\Form\TextType
          arguments: ["@security.context"]

1 Comment

mkay you've overriden the form-type that was exactly what i expected :D

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.