Yii:规则'allowEmpty'=> true仍然加注'不能为空'

qwe*_*tty 1 php yii cactiverecord yii-validation

我对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,在更新视图中它可以为空.

我不知道发生了什么,但一小时前它有效,但现在却没有.当我选择文件时,我得到'照片路径不能为空'

请帮忙 :)

Mar*_*lea 6

它不能同时需要和空.如果您在更新时要求它为空,请添加到第二个规则'on'=>'update'