开发者

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->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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜