开发者

Can't set validationErrors from beforeFilter

开发者 https://www.devze.com 2023-03-23 20:48 出处:网络
I can\'t set the valitationErrors from beforeFilter. Why? function beforeFilter () { if ($this->Session->check(\'errors\')) {

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->v开发者_JAVA百科alidationErrors" and none of them seem to work. When I go to the view, Debug Kit reports that the $this->validationErrors variable is empty.


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.


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. :)

0

精彩评论

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

关注公众号