Piotr
Piotr

Reputation: 29

Unset validate rules in CakePHP

I want unset validate rules in beforValidate but I have notices:

Notice (8): Indirect modification of overloaded property User::$validate has no effect

My code:

function beforeValidate($options = array()) {
    if (empty($this->data[$this->name]['name']) && empty($this->data[$this->name]['name2'])) {
        unset(
                $this->validate['name'], $this->validate['name2']
        );
    }
    return true;
}

How can I unset rules without notices?

Upvotes: 1

Views: 4636

Answers (1)

Dave
Dave

Reputation: 29121

First step is to usually try the Amazing Online CakePHP Book.

If you do that, you'll notice there's a section on how to remove validation rules.

Upvotes: 7

Related Questions