diogocarmo
diogocarmo

Reputation: 970

Can't set validationErrors from beforeFilter

I can't set the valitationErrors from beforeFilter. Why?

function beforeFilter () {
    if ($this->Session->check('errors')) {
        $this->validationErrors = array ('Question' => array('text' => 'notEmpty'));
    }
}

I tried both "$this->validationErrors" and "$this->Model->validationErrors" and none of them seem to work. When I go to the view, Debug Kit reports that the $this->validationErrors variable is empty.

Upvotes: 0

Views: 145

Answers (2)

diogocarmo
diogocarmo

Reputation: 970

Nevermind, I just figured it out that when you change validationErrors, the model you use to call it, is the model it will validate. So if you want to validate Questions, you should call $this->Question->validationErrors = ...

Thanks everyone. :)

Upvotes: 0

Anh Pham
Anh Pham

Reputation: 5481

I have never tried it, but maybe the model hasn't been init at that stage. You may need to save that for use in the actual action.

Upvotes: 1

Related Questions