Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.
like image 493
a53-416 Avatar asked Jul 01 '13 17:07

a53-416


1 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.

like image 102
Nicolai Fröhlich Avatar answered Nov 07 '22 11:11

Nicolai Fröhlich