webyjh 2011-12-31 12:35:46 2391次浏览 2条回复 0 0 0
public function rules() {
    // NOTE: you should only define rules for those attributes that
    // will receive user inputs.
    return array(
        array('front_img', 'file', 'types'=>'jpg, gif, png'),

不选文件就通不过验证,限制上传的类型同时也限制了必填,怎么设置选填,只有选了文件的时候才检查类型呢?

  • 回复于 2011-12-31 13:44 举报

    array('front_img','file','types'=>'jpg,gif,png','allowEmpty'=>true),

    添加allowEmpty,还有先插入数据库再上传,这样验证才正常

  • 回复于 2011-12-31 20:00 举报

    受教~~~

您需要登录后才可以回复。登录 | 立即注册