0

我是世界的新手,sf2我正在努力学习它。我安装TrSteelCkEditorBundle了作曲家,现在我试图让编辑器出现在视图中。我的捆绑包在AppKernel.

作为初学者,我的问题是:我必须做些什么才能让它发挥作用?我把这段代码粘贴到渲染中

$form = $this->createFormBuilder()
        ->add('title', 'text')
        ->add('content', 'ckeditor', array(
            'transformers' => array(),
        ))
        ->getForm();

在树枝视图中,我有第 6 行:

{{ form_widget(form) }}

但我收到一个错误:

An exception has been thrown during the rendering of a template ("Catchable Fatal Error: 
Argument 1 passed to Symfony\Component\Form\FormRenderer::searchAndRenderBlock() 
must be an instance of Symfony\Component\Form\FormView, 
instance of Symfony\Component\Form\Form given, called in 
/Applications/mamp/htdocs/Sf2/app/cache/dev/twig/5c/eb/e10823d760716de7f56b39640e79.php 
on line 29 and defined in 
/Applications/mamp/htdocs/Sf2/vendor/symfony/symfony/src/Symfony/Component/Form/FormRenderer.php
line 131") in amTestBundle:Default:index.html.twig at line 6.

如果有人有解决这个问题的线索,那将对我有很大帮助。谢谢你。

4

1 回答 1

0

{{ form_widget(form) }}不起作用,因为您的变量$form是表单本身。为了让 Twig 为其创建小部件,您必须将其发送到 Twig 模板:

$form->createView()

以下是您在 controllerAction 中返回时的示例:

return $this->render(
        'AcmeFooBundle:Acme:template.html.twig',
        array('form' => $form->createView()) //Here you see the createView()
    );
于 2013-01-17T22:55:46.947 回答