2016-03-07 61 views
1

我試圖在編輯表單中只創建一個標準的「created_at」字段。繼the doc你必須添加以下配置:EasyAdminBundle實體表單字段自定義

MyEntity: 
     form: 
      fields: 
       - { property: 'created_at', type_options: { widget: 'single_text' } } 

但它引發以下錯誤:

An Exception was thrown while handling: The option "widget" does not exist. Defined options are: "action", "allow_extra_fields"... 

有什麼明顯的添加/修改?

回答

3

如果你想使字段只讀的,你應該使用「已禁用」選項:

MyEntity: 
    form: 
     fields: 
      - { property: 'created_at', type_options: { disabled: true } } 

如果這不適合你,你可以嘗試明確設置表單類型?

MyEntity: 
    form: 
     fields: 
      - { property: 'created_at', type: 'datetime', type_options: { widget: 'single_text' } } 
+1

您也可以使用'read_only:true'而不是'disabled',但我不知道兩者之間有什麼區別。 –

+0

是的,我不得不添加類型參數。謝謝。應該更新文檔嗎? – COil