Php Yii,使用CMultiFileUpload上传文件
我是Yii的新手,所以不要生气。我搞不懂CUploadFile是怎么工作的。我有我的视图文件:Php Yii,使用CMultiFileUpload上传文件,php,yii,Php,Yii,我是Yii的新手,所以不要生气。我搞不懂CUploadFile是怎么工作的。我有我的视图文件: <div class="form form-custom"> <?php $form=$this->beginWidget('CActiveForm', array( 'id'=>'image-temp-form', 'enableAjaxValidation'=>false, 'htmlOptions'=>array('enctyp
<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(); ?>
我的模型是:
公车型;
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'),
);
}
外翻顺利进行,直到我尝试上传到控制器。我在CUploadedFile::getInstance()中作为参数放置的所有内容;结果为空 必须为file变量指定一条规则,强制其为file类型
array('car_type', 'file', 'types'=>'jpg, gif, png')
参考资料
尝试在模型规则数组中添加此行(“图像”、“汽车类型”、“类型”=>“jpg、gif、png”、“allowEmpty”=>true),
array('car_type', 'file', 'types'=>'jpg, gif, png')