Fixes the bug that using CFileValidator causes an error about accessing a method of a non-object

This commit is contained in:
qiang.xue
2009-10-18 19:58:59 +00:00
parent 5bd2352e0f
commit bb5ef901cb
2 changed files with 10 additions and 8 deletions

View File

@@ -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);
}
}