简体   繁体   中英

Yii: rules 'allowEmpty'=>true still raise 'cannot be blank'

I have a problem with CActiveRecord.rules

public function rules(){
    return array(
        array('photo_path', 'required', 'on'=>'insert'),
        array('photo_path', 'file', 'types'=>'jpg, gif, png', 'allowEmpty'=>true),
    );
}

Photo_path should be required only when the model is created, in update view it can be empty.

I dont know what happends, but one hour ago it works, but now it doesn't. When I choose file I get 'photo path cannot be blank'

Please help :)

It can not be required and empty in the same time. If you are looking for it to be empty on update then add to the second rule 'on' => 'update'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM