Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony Type error: Too few arguments to function FormRenderer::renderBlock()

Tags:

forms

symfony

I got a Form that must to handle the helpdesk requests in Symfony 3.3, i will render this using twig.

Controller

/**
 * @Route("/helpdesk/apri_ticket", name="helpdesk_apri")
 */
public function helpdeskNewAction(Request $request) {

    $entity = new HelpDesk();

    $form = $this->createFormBuilder($entity)
        ->add('title',TextType::class,array(
            'label' => 'Titolo',
            'attr' => array('class' => 'form-control')
        ))
        ->add('type',ChoiceType::class, array(
            'choices' => array(
                'Scegli...' => '0',
                'Assistenza' => '1',
                'Problema' => '2',
                'Errore' => '3'
            )
        ))
        ->add('message', TextType::class, array(
            'label' => 'Messaggio',
            'attr' => array('class' => 'form-control')
        ))
        ->add('submit',SubmitType::class, array(
            'label' => 'Apri Ticket',
            'attr' => array('class' => 'btn-success')
        ))
        ->getForm();

    $form->handleRequest($request);

    if($form->isSubmitted() && $form->isValid()) {
        print 'ok';
    }

    return $this->render('help/help.create.html.twig', array(
        'form' => $form->createView())
    );
}

Here is the easy twig template:

{{ form_start(form) }}
    {{ form_widget(form.title) }}
    {{ form_widget(form.type) }}
    {{ form_widget(form.message) }}
{{ form_end() }}

Here is the Error:

Type error: Too few arguments to function Symfony\Component\Form\FormRenderer::renderBlock(), 0 passed in /vendor/twig/twig/lib/Twig/Environment.php(462) : eval()'d code on line 83 and at least 2 expected

What's wrong with this? FormRenderer::renderBlock ask for at least 2 arguments, FormView and BlockName and optional an array containing variables. This is the first time I got this error and I don't know what is this BlockName.

like image 496
andreaem Avatar asked Dec 03 '22 21:12

andreaem


1 Answers

The error comes from cached files, so in a first step, you should delete all files/dirs in /var/cache/.

Do it manually (not by console)

The form ending should be:

{{ form_end(form) }}
like image 123
Michał G Avatar answered Jan 10 '23 08:01

Michał G