开发者

symfony/doctrine custom validation

开发者 https://www.devze.com 2023-03-23 09:28 出处:网络
I am struggling with the custom validation in symfony/doctrine. I made three widgets: sfWidgetFormDateTimeAmPm,

I am struggling with the custom validation in symfony/doctrine. I made three widgets:

  • sfWidgetFormDateTimeAmPm,
  • sfWidgetFormDateAmPm and
  • sfWidgetFormTimeAmPm to add the am/pm to the standard 24 hours date/time format.

Similar I created three validator classes:

  • sfValidatorDateTimeAmPm,
  • sfValidatorDateAmPm and
  • sfValidatorTimeAmPm.

I added this classes to my doctrine basic class like this:

class EventForm extends BaseEventForm {

 public function configure(){
    parent::configure();
    /* custom widget */
    $this->widgetSchema['start_date']            = new sfWidgetFormDateTimeAmPm();
    $this->widgetSchema['end_date']              = new sfWidgetFormDateTimeAmPm();
    $this->widgetSchema['repeat_end_after_date'] = new sfWidge开发者_JAVA技巧tFormDateTimeAmPm();
    $this->widgetSchema['created_at']            = new sfWidgetFormDateTimeAmPm();
    $this->widgetSchema['updated_at']            = new sfWidgetFormDateTimeAmPm();

    $this->setValidators['start_date']            = new sfValidatorDateTimeAmPm();
    $this->setValidators['end_date']              = new sfValidatorDateTimeAmPm();
    $this->setValidators['repeat_end_after_date'] = new sfValidatorDateTimeAmPm(array('required' => false));
    $this->setValidators['created_at']            = new sfValidatorDateTimeAmPm();
    $this->setValidators['updated_at']            = new sfValidatorDateTimeAmPm();

    $this->validatorSchema->setPostValidator(
        new sfValidatorDoctrineUnique(array('model' => 'Event', 'column' => array('id')))
    );
    $this->widgetSchema->setNameFormat('event[%s]');
    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

... but it does not work. Could someone advice me. I have no clue, what it did wrong or what I have forgotten to do.

Thanks Andreas


$this->setValidators['field'] is wrong, you want $this->validatorSchema['field'] = new WhateverValidator().

0

精彩评论

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

关注公众号