Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

validate() returns false but getErrors() returns an empty array - Yii

Tags:

php

yii

I am building a yii application. Heres the code -:

    $id = 2;

    $model = Page::model()->findByPk(2);
    $model->title = 'HeyMan';

    if($model->validate())
    {
        echo 'Validation retuned true';
    }
    else
    {
        $array = $model->getErrors();
        $message = 'Validation returned false';
    }

And the result is that the validate() returns false while getErrors() returns an empty array. Whats the problem here ? Thanks

like image 812
sanchitkhanna26 Avatar asked Aug 30 '13 15:08

sanchitkhanna26


1 Answers

Did you use the beforeSave function in your model? Then make sure to return the parent beforeSave:

return parent::beforeSave();
like image 87
Michiel Avatar answered Nov 14 '22 21:11

Michiel