Asked  1 Year ago    Answers:  5   Viewed   17 times

When I create a form inside my controller action like this:

$form = $this->createFormBuilder()

return array(
    'form' => $form

... and I try to render this form in a twig template like this:

    <form action="{{ path('...') }}" method="post">
        {{ form_widget(form.field_name) }}

... the form_widget invocation produces the following exception/error:

An exception has been thrown during the rendering of a template ("Catchable Fatal Error: Argument 1 passed to SymfonyComponentFormFormRenderer::searchAndRenderBlock() must be an instance of SymfonyComponentFormFormView, instance of SymfonyComponentFormForm given, called in ...

How can I resolve this issue?



You have to pass an instance of SymfonyComponentFormFormView instead of SymfonyComponentFormForm to your view.

Fix this using ...

... ->getForm()->createView();

FormBuilder::getForm builds the Form object ... Form::createView then creates a FormView object.

Saturday, May 29, 2021

@CharlotteDunois pointed this out, but Twig 2.0 requires >=PHP7.0, so in your environment (php 5.6) you can't use Twig 2.0. From the Twig official documentation:


Twig needs at least PHP 7.0.0 to run.

Notice that for PHP5.x branch you still have Twig 1.x aviable

Thursday, April 1, 2021

Just use this part of code and it works

if($loginForm->isSubmitted() && $loginForm->isValid()){
  //don't forget the return statement

if($registerForm->isSubmitted() && $registerForm->isValid()){
  //don't forget the return statement
Saturday, May 29, 2021

Yes you can, look at the documentation, if you add seven DailyStats entities to your week entity then symfony2 will render those seven inputs that you want, please check

class TaskController extends Controller
      public function newAction(Request $request)
           $task = new Task();

           // dummy code - this is here just so that the Task has some tags
           // otherwise, this isn't an interesting example
           $tag1 = new Tag();
           $tag1->name = 'tag1';
           $task->getTags()->add($tag1); // any new related entity you add represents a new embeded form
           $tag2 = new Tag();
           $tag2->name = 'tag2';
           // end dummy code

           $form = $this->createForm(new TaskType(), $task);


           if ($form->isValid()) {
               // ... maybe do some form processing, like saving the Task and Tag objects

           return $this->render('AcmeTaskBundle:Task:new.html.twig', array(
               'form' => $form->createView(),
Saturday, May 29, 2021

The third argument to PyMongo's update() is upsert and must be passed a boolean, not a dictionary. Change your code to:

self.word_counts[source].update({'date':posttime}, {"$inc" : words}, True)

Or pass upsert=True as a keyword argument:

self.word_counts[source].update({'date':posttime}, {"$inc" : words}, upsert=True)

Your mistake was likely caused by reading about update() in the MongoDB docs. The JavaScript version of update takes an object as its third argument containing optional parameters like upsert and multi. But since Python allows passing keyword arguments to a function (unlike JavaScript which only has positional arguments), this is unnecessary and PyMongo takes these options as optional function parameters instead.

Sunday, August 1, 2021
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :