1

在 Doctrine Record 对象中,我可以添加以下方法来验证数据:

protected function validate()
{
    if (empty($this->first_name) && empty($this->last_name) && empty($this->company)) {
        $this->getErrorStack()->add('company', 'You must fill in at least one of the following: First Name, Last Name, Company');
    }
}

如何将类似代码添加到附加的模板对象?

4

1 回答 1

1

I tried also, but it looks like it can't be done in behaviour class. To avoid that, in preValidate method I placed code that would check that additional columns.

I would recommend you to not change validate() method, but to use preValidate($event) and postValidate($event) public methods. It should look like:

public function preValidate(Doctrine_Event $event)
{
   ... your custom validation logic...
   parent::preValidate($event) ;
}
于 2010-10-22T17:50:31.307 回答