开发者

symfony 1.4 admin generator unset fields

I've used the "doctrine:generate-admin" task. Everything is working but I want to use the generator.yml file to unset some form fields there rather than having to unset them in the Form class itself. Things like "updated_at" I only ever need saved when the object is updated but I don't want them displayed on any forms, and therefore I won't get any form 开发者_运维知识库validation errors.

Is this possible? I can't find anything on the reference page for the generator that would let me do this, the fields configuration only seems to allow for changing the label/credentials etc.


You need to simply choose fields you want to display:

config:
  form:
    display:
      Content: [title, body, author]
      Admin:   [is_published, expires_at]

It's weird you didn't find it on the reference page. Here you go: http://www.symfony-project.org/reference/1_4/en/06-Admin-Generator (navigate to form -> display).

Edit:

Admin generator uses sfModelGeneratorConfiguration::getFormFields() method to retrieve list of fields to render. It only takes all fields if you won't specify the 'display' option.

Is it all the fields are rendered or just some of them? If it's the later than you might have something overloaded in your form (for example configure() method).


try this:

config:
  list:
    hide: [created_at, updated_at]

http://www.symfony-project.org/reference/1_4/en/06-Admin-Generator#chapter_06_sub_hide


Apart from hiding the fields in config/generator.yml of the admin module, as stated above, you should unset them in the related form. So if you want to hide the created_at and updated_at fields of a Timestampable model, alter the configure() method in lib/form/doctrine/ModelForm.class.php to

public function configure()
{
    unset($this['created_at'],$this['updated_at']);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜