if($_FILES['Pilgrims']['name']['foto'] !=0)
public function rules()
{
return array(
array('fotoUploader', 'required'),
array('fotoUploader', 'file', 'types'=>'jpg, gif, png'),
);
}
//было photo
$this->foto = md5(time()) . '.jpg';
afterSave()
и beforeSave()
реализовать. public function beforeSave()
{
$this->photo = md5(time()) . '.jpg'; //генерация имени
return parent::beforeSave();
}
public function afterSave()
{
$this->fotoUploader->saveAs('/path/to/upload/folder/'. $this->foto);
}
foto
, то код нужно написать так.class Item extends CActiveRecord
{
public $fotoUploader;
public function rules()
{
return array(
array('fotoUploader', 'file', ..., 'on' => 'upload'),
);
}
public function beforeSave()
{
$this->photo = md5(time()) . '.jpg'; //генерация имени
}
public function afterSave()
{
$this->foto->saveAs('/path/to/upload/folder/'. $this->foto);
}
}
//...
$model->fotoUploader = CUploadedFile::getInstance($model,'foto');
$model->save();