开发者

Symfony Adding and Dealing With Custom Form Fields

I am using Symfony with propel to generate a form called BaseMeetingMeetingsForm.

In MeetingMeetingsForm.class.php I have the following configure method:

public function configure() {
    $this->useFields(array('name', 'group_id', 'location', 'start', 'length'));

    $this->widgetSchema['invited'] = new myWidgetFormTokenAutocompleter(array("url"=>"/user/json"));
}

In MeetingMeetings.php my save method is simply:

  public function save(PropelPD开发者_运维知识库O $con = null) {
    $this->setOwnerId(Meeting::getUserId());

    return parent::save($con);
  }

However propel doesn't know about my custom field and as such doesn't do anything with it. Where and how to I put in a special section that can deal with this form field, please be aware it is not just a simple save to database, I need to deal with the input specially before it is input.

Thanks for your time and advice,


You have to define a validator (and/or create your own). The validator clean() method returns the value that needs to be persisted.

In Doctrine (I don't know Propel) the form then calls the doUpdateObject() on the form, which in turns calls the fromArray($arr) function on the model.

So if it's already a property on your model you'll only need to create the validator. If it's a more complex widget, you'll need to add some logic to the form.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜