0
即時通訊這裏再次出現一個新問題。我正嘗試使用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」選項關聯數組? – Refilon 2014-11-08 22:44:55
@ Deer-Outdoor.nl,類似的東西: '<?php $ form = $ this-> beginWidget('CActiveForm',array( 'id'=>'miscellaneous-pages-form', 'enableAjaxValidation' => false, 'htmlOptions'=' – 2014-11-19 17:57:45