我正在尝试在 CjuiDialog 小部件中上传文件,我正在 Controller 类中打印上传的文件名但它返回 null,我试图打印 $POST 数组,图像数组返回空,请参见下面的代码,
我的控制器代码,
public function actionUpload()
{
$model=new UploadModel();
echo var_dump($_POST);
if(isset($_POST['UploadModel']))
{
$model->image=CUploadedFile::getInstance($model,'image');
echo"image-->".$model->image;
$this->redirect(array("create"));
}
}
我的查看代码,
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'uploadfile-form',
//'enctype'=>'multipart/form-data',
'method'=>'post',
'htmlOptions' => array('enctype' => 'multipart/form-data'),
'action'=>'upload',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php
echo $form->errorSummary($model); ?>
<?php echo $form->labelEx($model,'Base Name',array('text-align'=>'right','style'=>'display:inline-block'))." "; ?>
<?php echo $form->textField($model,'name',array('size'=>60,'maxlength'=>128)); ?>
<?php echo $form->error($model,'name'); ?>
<br>
<?php echo $form->labelEx($model,'Active',array('style'=>'display:inline-block'))." "; ?>
<?php echo $form->checkBox($model,'is_active',array('size'=>60,'maxlength'=>128)); ?>
<?php echo $form->error($model,'is_active'); ?>
<br>
<?php
echo $form->fileField($model, 'image');
?>
<br><br>
<?php echo CHtml::submitButton( 'Upload',array('background-style'=>'none')); ?>
<?php echo CHtml::button('Cancel',array('background-style'=>'none','onclick'=>'$("#BCEditSource").dialog("close"); return false;')); ?>
<?php $this->endWidget(); ?>