我需要更新模态窗口并在单击编辑按钮时显示它。
控制器:
public function actionUpdateAjax($id)
{
$contratos = ZfContratos::model()->findByPk($id);
$this->renderPartial('//ZfContratos/_form_update', array('model'=>$contratos), false, true);
}
INDEX:
<?php $this->beginWidget(
'bootstrap.widgets.TbModal',
array('id' => 'actualizar_contrato')
); ?>
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h4>Actualizar contrato</h4>
</div>
<div class="modal-body">
<?php $this->renderPartial('//ZfContratos/_form_update', array('model'=>$contrato));?>
</div>
<div class="modal-footer">
<?php $this->widget(
'bootstrap.widgets.TbButton',
array(
'label' => 'CANCELAR',
'url' => '#',
'htmlOptions' => array('data-dismiss' => 'modal'),
)
); ?>
</div>
<?php $this->endWidget(); ?>
AND VIEW _contratos
此刻我有这个:
<?php echo CHtml::link('EDITAR', array('//ZfInmuebles/UpdateAjax', 'id'=>$data->zf_contrato_id), array('class'=>'btn', 'id'=>'vermas')); ?>
但是我需要这是一个ajaxbutton或ajaxlink,刷新div&#34; actualizar_contrato&#34;并展示它。
答案 0 :(得分:0)
这只是一个参考实现,可以让您了解如何执行此操作,根据您的要求进行修改
// your view
// Button to trigger modal
<?php echo CHtml::ajaxLink('EDITAR',array('//ZfInmuebles/UpdateAjax', 'id'=>$data-> zf_contrato_id), array(
'type'=>'POST',
"success"=>'js:function(html){
$("#actualizar_contrato >.modal-body").html(html);
$("#actualizar_contrato").modal("show");
}
'));?
.....
// modal
<?php $this->beginWidget(
'bootstrap.widgets.TbModal',
array('id' => 'actualizar_contrato')
); ?>
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h4>Actualizar contrato</h4>
</div>
<div class="modal-body">
<?php
$contrato = new ZfContratos;
$this->renderPartial('//ZfContratos/_form_update', array('model'=>$contrato));
?>
</div>
<div class="modal-footer">
<?php echo CHtml::ajaxLink('Save', // Link Text
array('//ZfContratos/update', 'id'=>$data->zf_contrato_id), //url
array(// ajaxOptions
'data'=> 'js:$("#id_of_the_form").serialize()' ,
'type'=>'POST',
'success'=>'js:function(html){$("#actualizar_contrato >.modal-body").html(html) }'
)
)
);?>
<?php $this->widget(
'bootstrap.widgets.TbButton',
array(
'label' => 'CANCELAR',
'url' => '#',
'htmlOptions' => array('data-dismiss' => 'modal'),
)
); ?>
</div>
<?php $this->endWidget(); ?>
.....
现在在您的控制器中修改如下所示
//ZfContratos Controller
public function actionUpdate(){
// Your regular logic for saving
if(Yii::app()->request->isAjaxRequest){
if($model->save()){
$this->renderPartial("_mvsavedView",array('model'=>$model)) //OR echo "Saved Successfully";
} else {
print_r($model->getErrors());
}
Yii::app()->end();
}
}