Symfony controller embedd error: The controller for URI "/_fragment" is not callable

I'm calling a render like so in my Twig template (line 18)

{{ render(controller('AcmeReadingBundle:Default:newAction')) }}

And the controller is

public function newAction(Request $request)
    { 
      $message = new Message();
      $form = $this->createFormBuilder($message)
        ->add('body', 'text')
        ->add('save', 'submit')
        ->getForm();

      $form->handleRequest($request);

      return $this->render('AcmeReadingBundle:Default:new.html.twig', array(
          'form' => $form->createView(),
        ));
    }

And the new.html.twig file is

{{ form(form) }}

I keep getting this error:

An exception has been thrown during the rendering of a template ("The controller for URI "/_fragment" is not callable.") in AcmeReadingBundle:Default:show.html.twig at line 18.

Answers


Solution:

You're trying to render a template ( '...new.html.twig' ) using controller() instead of a controller/action!

change your render function to :

{{ render(controller('AcmeReadingBundle:Default:new')) }}

(notice: no "...Action" in method name)


Tip:

The _fragment exception is mostly thrown if there is something wrong with the controller name specified.

i.e. missspelling the controller/action name is often the reason for this exception.


Further reading:

Take a look at this cookbook article.


I agree with @nifr You're trying to render a template ( '...new.html.twig' ) using controller() instead of a controller/action!

change your render function to :

{{ render(controller('AcmeReadingBundle:Default:new')) }}

(notice: no "...Action" in method name)

Below is more if above solution is not giving you solution.

  1. Check if a defined function in the controller is a public function. In my case I have defined that protected.

Thanks,

Anirudh Sood.


Need Your Help

Fastest way to check if a value exists in a list

python performance list

What is the fastest way to know if a value exists in a list (a list with millions of values in it) and what its index is?