我想删除图像并在更新视图(yii)中重新显示上传的字段。
- 有一张图片已上传。
- 当用户删除此图像时。
- 那时图像将被删除,上传
$form->filefield
将出现在图像位置。
这是视图
<div id="forAjaxRefresh"><img src="<?php echo $file; ?>" width="150px" /></div>
<?php echo CHtml::ajaxLink('clickMe', array('ajax'), array('update'=>'#forAjaxRefresh'));?>
这是控制器
public function actionAjax()
{
$model=new CompanyLicense('search');
//$this->render('update', array('model'=>$model,'test'=>'test'), false, true);
//echo "$form->labelEx($model,'file_path');
//$form->fileField($model,'file_path', array('class'=>'input-file'));
//$form->error($model,'file_path'); ";
//echo "$form->labelEx($model,'file_path')";
echo 'OK';
}
当我尝试喜欢它时。它在 处显示“OK”。但我想在 . 我该怎么办?请帮我。
===============+++++++++++++++++++++++++++++++++==== =================================
最新的mvc
模型没什么变化
控制器
public function actionAjax($id)
{
$model=new CompanyLicense();
//$this->render('uploadfield', array());
//echo "$form->labelEx($model,'file_path');
//$form->fileField($model,'file_path', array('class'=>'input-file'));
//$form->error($model,'file_path'); ";
//echo "$form->labelEx($model,'file_path')";
echo $this->renderPartial('uploadfield',array('model'=>$model),false,true);
/*
$model=Company::model()->findByPk($_GET['id']);
if($model){
$file = '/images/'. $model->id . '/'. $model->file_path;
unlink(dirname(__FILE__) . '/../../..'.$file);
}
<br />
*/
}
查看(_form.php)
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'company-license-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,'company_id'); ?>
<?php
$records = Company::model()->findAll();
$list = CHtml::listData($records, 'id', 'name');
?>
<?php echo $form->dropDownList($model,'company_id', $list, array('prompt'=>'Please select a Company')); ?>
<?php echo $form->error($model,'company_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'license_no'); ?>
<?php echo $form->textField($model,'license_no',array('size'=>50,'maxlength'=>50)); ?>
<?php echo $form->error($model,'license_no'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'license_name'); ?>
<?php echo $form->textField($model,'license_name',array('size'=>60,'maxlength'=>200)); ?>
<?php echo $form->error($model,'license_name'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'annualfee'); ?>
<?php echo $form->textField($model,'annualfee',array('size'=>10,'maxlength'=>10)); ?>
<?php echo $form->error($model,'annualfee'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'expire_date'); ?>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'name'=>'expire_date',
'model'=>$model,
'value' => $model->expire_date,
'options'=>array(
'showAnim'=>'fold',
'dateFormat' => 'yy-mm-dd',
),
'htmlOptions'=>array(
'style'=>'height:20px;'
),
));
?>
<p> Expire Date must be greater than Current Date.</p>
<?php echo $form->error($model,'expire_date'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'notification_days'); ?>
<?php echo $form->textField($model,'notification_days'); ?><p> Notification Days must be between 7 and 90.</p>
<?php echo $form->error($model,'notification_days'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'description'); ?>
<?php echo $form->textArea($model,'description',array('rows'=>6, 'cols'=>50)); ?>
<?php echo $form->error($model,'description'); ?>
</div>
<div class="row" id="file_upload">
<?php
$file = '/images/'. $model->id . '/'. $model->file_path;
if (file_exists(dirname(__FILE__) . '/../../..'.$file)){
echo '<img src="http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . $file.'" width="150px" />' ;
}else{
?>
<div class="row">
<?php echo $form->labelEx($model,'file_path'); ?>
<?php echo $form->fileField($model,'file_path', array('class'=>'input-file')); ?>
<?php echo $form->error($model,'file_path'); ?>
</div>
<?php
}
?>
</div>
<div id="forAjaxRefresh"><img src="http://<?php echo $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . $file; ?>" width="150px" /></div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
<?php echo CHtml::ajaxLink('remove', array('ajax'), array('update'=>'#forAjaxRefresh')); ?>
<?php
echo CHtml::ajaxLink( 'delete', array( 'companylicense/ajax', 'id'=>$model->id), array('type'=> 'GET', 'update' => '#forAjaxRefresh') );
?>
<?php echo CHtml::ajaxLink('remove2', array('url'=>array('companylicense/ajax', 'id'=>$model->id),
), array('update'=>'#forAjaxRefresh')); ?>
查看 (uploadfield.php)
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'company-license-form',
'enableAjaxValidation'=>false,
'htmlOptions' => array('enctype' => 'multipart/form-data'),
)); ?>
<?php echo $form->labelEx($model,'file_path'); ?>
<?php echo $form->fileField($model,'file_path', array('class'=>'input-file')); ?>
<?php echo $form->error($model,'file_path'); ?>
<?php $this->endWidget(); ?>
请帮我!!!