i would like to know how?
this is my upload controller
public function actionUpdate($id)
{
$model=$this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Nacional']))
{
$model->attributes=$_POST['Nacional'];
$file_image = CUploadedFile::getInstance($model,'foto');
if ( (is_object($file_image) && get_class($file_image)==='CUploadedFile'))
$model->foto = $file_image;
if($model->save())
if (is_object($file_image))
$model->foto->saveAs(Yii::app()->basePath.'/../images/'.$model->foto);
//$this->redirect(array('view','id'=>$model->id_nacional));
}
$this->render('update',array(
'model'=>$model,
));
}
the rules of my model
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('entidad, cargo, nombres, apellidos, email, sexo, cedula, fecha_nacimiento, foto, llenado_por', 'required'),
array('sexo, usuario_a', 'numerical', 'integerOnly'=>true),
array('num_confirmacion', 'length', 'max'=>20),
array('entidad, cargo, email, conyuge, llenado_por', 'length', 'max'=>75),
array('nombres, apellidos, control_ip', 'length', 'max'=>50),
array('cedula', 'length', 'max'=>25),
array('foto', 'length', 'max'=>100),
array('foto', 'unsafe'),
array('foto','file','types'=>'jpg, jpeg, png, gif','maxSize'=>1024*1024*0.5, // 0.5MB
'tooLarge'=>'The file was larger than 500 KB. Please upload a smaller file.'),
array('fecha_nacimiento, control_i', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id_nacional, num_confirmacion, entidad, cargo, nombres, apellidos, email, conyuge, sexo, cedula, fecha_nacimiento, foto, llenado_por, control_i, control, control_ip, usuario_a', 'safe', 'on'=>'search'),
);
}
and my view
<div class="row">
<?php echo $form->labelEx($model,'foto'); ?>
<?php echo CHtml::activeFileField($model, 'foto');?>
<!-- <?php echo $form->fileField($model, ‘foto’, array(‘id_nacional’=>‘foto’)); ?>–>
<?php echo $form->error($model,'foto'); ?>
</div>
I commented the part of fileField and change it for CHtml::activeFileField because CHtml::activeFileField is the one to work with CUploadedFile::getInstance($model,‘foto’); according the manual of yii frameworl
but i still get no value of the CUploadedFile::getInstance($model,‘foto’); 