2013-01-17 18 views
0

我是sf2的世界新人,我正在努力學習它。 我用作曲者安裝了TrSteelCkEditorBundle,現在我試圖在視圖中獲取編輯器。 我的包在AppKernel中處於活動狀態。如何在Symfony2中使用TrSteelCkEditorBundle?

作爲一個初學者,我的問題是: 我需要做什麼才能使它工作? 我把這個代碼並將其粘貼在價值渲染

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

如果有人有線索解決它,它會幫助我很多。 謝謝。

回答

0

{{ form_widget(form) }}不起作用,因爲您的$form變量是表單本身。爲了得到嫩枝爲它創建的窗口小部件,你必須把它與發送到嫩枝模板:

$form->createView() 

下面是當你在你controllerAction返回一個例子:

return $this->render(
     'AcmeFooBundle:Acme:template.html.twig', 
     array('form' => $form->createView()) //Here you see the createView() 
    ); 
+0

謝謝,我忘記了那個重要的細節。現在我有一個錯誤:''Route「route_name」does not exist'。所以我必須在某處定義路由,所以控制器知道在哪裏找到表單。 – Gnarok