2015-08-19 48 views
1

我在實體中有一個數組類型,我想將它添加到表單類型中作爲隱藏字段。我嘗試了以下,但它不起作用。它只是殺死瀏覽器。如何在symfony2中隱藏表單中的實體的數組類型

任何幫助將不勝感激。

//Entity 
    class Test{ 

     /** 
     * @ORM\Column(name="test_image_files", type="array",nullable=true) 
     */ 
     private $testImages; 

     /** 
     * @return mixed 
     */ 
     public function getTestImages() 
     { 
      return $this->testImages; 
     } 

     /** 
     * @param mixed $testImages 
     */ 
     public function setTestImages($testImages) 
     { 
      $this->testImages = $testImages; 
     } 

    } 

// FormType

class TestType extends AbstractType 
{ 
    public function buildForm(FormBuilderInterface $builder, array $options) 
    { 
     $builder->add('testImages','hidden'); 
    } 
} 

//枝杈

{{ form_widget(form.testImages) }} 
+0

你甚至需要那個領域嗎? –

+0

你有沒有嘗試在將數組放入表單之前序列化數組?或將其轉換爲文本。我相信表單字段是非常基本的,他們可以處理文本和數字(和文件),我還沒有嘗試過更多'複雜的對象'作爲數組。 – Erwin

回答

0

這將幫助你處理當前形勢下,

回聲form_widget(form.testImages)<div style="display:none"></div>

我希望這會有所幫助。

相關問題