在Yii上传文件不显示图像名称/路径
问题描述:
即时通讯这里再次出现一个新问题。我正尝试使用yii上传功能上传文件。在Yii上传文件不显示图像名称/路径
一切都很好,免去了形象。这里是我的代码:
控制器:
public function actionUpdate($id)
{
$model=$this->loadModel($id);
$dir = Yii::getPathOfAlias('webroot.images.producten');
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Producten']))
{
$model->attributes=$_POST['Producten'];
$model->images=CUploadedFile::getInstance($model,'images');
$nf = $model->images;
if($model->save()){
$this->redirect(array('view','id'=>$model->id));
$model->images->saveAs($dir.'/'.$nf);
$model->images = $nf;
$model->save();
}
}
$this->render('update',array(
'model'=>$model,
));
}
形式:
<div class="row">
<?php echo $form->labelEx($model,'images'); ?>
<?php echo CHtml::activeFileField($model,'images'); ?>
<?php echo $form->error($model,'images'); ?>
</div>
型号:
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('naam, beschrijving, prijs', 'required'),
array('images,', 'file', 'allowEmpty'=>true,
'safe' => true,
'types'=> 'jpg, jpeg, png, gif',
'maxSize' => (1024 * 300), // 300 Kb
),
array('aangepast_door', 'numerical', 'integerOnly'=>true),
array('naam', 'length', 'max'=>50),
array('prijs, actieprijs', 'length', 'max'=>10),
//array('toegevoegd, aangepast', 'safe'),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('naam, beschrijving, prijs, actieprijs', 'safe', 'on'=>'search'),
);
}
请帮我得到这个工作。
答
首先将enctype =“multipart/form-data”添加到窗体标记中,或者将“enctype”选项添加到关联数组中,如果使用窗体小部件yo begin form。 如果它不会帮助你,请发帖var_dump($_POST)
结果
你是什么意思与添加“enctype”选项关联数组? – Refilon 2014-11-08 22:44:55
@ Deer-Outdoor.nl,类似的东西: ' beginWidget('CActiveForm',array( 'id'=>'miscellaneous-pages-form', 'enableAjaxValidation' => false, 'htmlOptions'=' – 2014-11-19 17:57:45