如何在Yii框架中创建带有确认对话框的链接?
假设我有
CHtml::link('Delete',array('wsrecruiteducation/delete','id'=>$model->EducID));
在删除数据之前,如何将上面的代码段转换为带有确认警报的删除链接?
答案 0 :(得分:29)
您只需要使用CHtml::link
的最后一个参数:
CHtml::link(
'Delete',
array('wsrecruiteducation/delete','id'=>$model->EducID),
array('confirm' => 'Are you sure?')
);
答案 1 :(得分:4)
你可以这样做:
CHtml::link( 'Delete', '#', array('submit'=>array('wsrecruiteducation/delete','id'=>$model->EducID), 'params'=>('returnUrl'=>'controller/action...'), 'confirm' => 'Are you sure?') );
returnUrl将是随请求一起发送的帖子项目,请确保在具有删除操作的控制器中进行类似的操作:
... if(!isset($_GET['ajax'])) $this->redirect(isset($_POST['returnUrl']) ? array($_POST['returnUrl']) : array('admin')); ...
答案 2 :(得分:0)
如果您想要使用确认对话框删除链接,请使用此
echo CHtml::link("Delete", '#', array(
'submit'=>array('controller/delete', "id"=>$model->id), 'confirm' => 'Are you sure you want to delete?'));