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

a53-416 picture a53-416 · Jul 1, 2013 · Viewed 16.1k times · Source

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.

Answer

Nicolai Fröhlich picture Nicolai Fröhlich · Jul 1, 2013

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.