2016-03-07 107 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