开发者

Doctrine 1.2: Adding validation method to record template

开发者 https://www.devze.com 2023-01-20 02:46 出处:网络
In a Doctrine Record object, I can add the following method to validate data: protected function validate()

In a Doctrine Record object, I can add the following method to validate data:

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, La开发者_高级运维st Name, Company');
    }
}

How do I add similar code to an attached Template object?


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) ;
}
0

精彩评论

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