diff --git a/CHANGELOG b/CHANGELOG index c49c270ef..10e47358e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,7 @@ Version 1.1b to be released --------------------------- +- Bug: Using CFileValidator causes an error about accessing a method of a non-object (Qiang) - Chg #574: session ID is no longer hashed for CDbHttpSession (Qiang) Version 1.1a October 1, 2009 diff --git a/framework/validators/CFileValidator.php b/framework/validators/CFileValidator.php index 76216b619..f3f7784fe 100644 --- a/framework/validators/CFileValidator.php +++ b/framework/validators/CFileValidator.php @@ -109,29 +109,30 @@ class CFileValidator extends CValidator { if($this->maxFiles > 1) { - if(null===$object->$attribute) - $object->$attribute = CUploadedFile::getInstances($object, $attribute); - if(array()===$object->$attribute) + $files=$object->$attribute; + if(!is_array($files)) + $files = CUploadedFile::getInstances($object, $attribute); + if(array()===$files) return $this->emptyAttribute($object, $attribute); - if(count($object->$attribute) > $this->maxFiles) + if(count($files) > $this->maxFiles) { $message=$this->tooMany!==null?$this->tooMany : Yii::t('yii', '{attribute} cannot accept more than {limit} files.'); $this->addError($object, $attribute, $message, array('{attribute}'=>$attribute, '{limit}'=>$this->maxFiles)); } else - foreach($object->$attribute as $file) + foreach($files as $file) $this->validateFile($object, $attribute, $file); } else { - if(null===$object->$attribute) + $file = $object->$attribute; + if(!$file instanceof CUploadedFile) { $file = CUploadedFile::getInstance($object, $attribute); if(null===$file) return $this->emptyAttribute($object, $attribute); - $object->$attribute = $file; } - $this->validateFile($object, $attribute, $object->$attribute); + $this->validateFile($object, $attribute, $file); } }