20

Twig テンプレートでそのようにレンダーを呼び出しています (18 行目)

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

そしてコントローラーは

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(),
        ));
    }

そして new.html.twig ファイルは

{{ form(form) }}

このエラーが発生し続けます:

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

2 に答える 2

34

解決:

controller/actionの代わりに使用して、テンプレート( '...new.html.twig' ) をレンダリングしようとしています!controller()

render関数を次のように変更します。

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

(注意: メソッド名に「...Action」はありません)


ヒント:

指定されたコントローラー名に何か問題がある場合、_fragment 例外がスローされます。

つまり、コントローラー/アクション名のスペルミスが、この例外の原因になることがよくあります。


参考文献:

このクックブックの記事をご覧ください。

于 2013-07-01T17:24:41.400 に答える