I’m total newbie in Yii so dont get mad. I cant figure out how CUploadFile works. I have my view file
<div class="form form-custom">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'image-temp-form',
'enableAjaxValidation'=>false,
'htmlOptions'=>array('enctype'=>'multipart/form-data' ),
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'car_type'); ?>
<?php
$this->widget('CMultiFileUpload', array(
'model'=>$model,
'attribute'=>'car_type',
//'name' => 'files',
'accept'=>'jpg|gif|png',
'denied'=>'File is not allowed',
'max'=>3,
));
?>
<?php echo $form->error($model,'car_type'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
My controller broken down to bits:
public function actionCreate()
{
$model=new EeCarTypes;
if ( isset( $_FILES['EeCarTypes']))
{
$images = $_FILES['EeCarTypes'];
$model->car_type = $images['name']['car_type'][0];
$uploadedFile = CUploadedFile::getInstance($model, 'car_type');
CVarDumper::Dump($uploadedFile, 10 ,true);
$uploadedFile->saveAs(Yii::app()->basePath . '/../images/upload/cartypes/'.'hehehe');
}
$this->render('create',array(
'model'=>$model,
));
}
and my model:
public $car_type;
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
// array('image', 'file','types'=>'jpg, gif, png', 'allowEmpty'=>true, 'on'=>'update'),
array('car_type', 'length', 'max'=>255),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('id, car_type', 'safe', 'on'=>'search'),
);
}
Everting goes smooth until I try to upload in controller. Everything I put as arguments in CUploadedFile::getInstance(); results in NULL;