如何在Symfony2中使用TrSteelCkEditorBundle?

时间:2013-01-17 22:47:34

标签: symfony ckeditor bundle

我是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.

如果有人有解决方法的话,它会对我有很大的帮助。 谢谢。

1 个答案:

答案 0 :(得分: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()
    );
相关问题