没用过1,但是翻了下代码,你的问题在rules.
array('img', 'file', 'allowEmpty'=>true, 'types'=>'bmp,jpg,png,gif'),
CFileValidator
如果验证的字段不通过的话会把该字段设置成 null
/**
* Raises an error to inform end user about blank attribute.
* Sets the owner attribute to null to prevent setting arbitrary values.
* @param CModel $object the object being validated
* @param string $attribute the attribute being validated
*/
protected function emptyAttribute($object, $attribute)
{
if($this->safe)
$object->$attribute=null;
if(!$this->allowEmpty)
{
$message=$this->message!==null?$this->message : Yii::t('yii','{attribute} cannot be blank.');
$this->addError($object,$attribute,$message);
}
}