php 如何使用 Yii 创建带有确认对话框的链接?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5246361/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create a link with confirmation dialog using Yii?
提问by sasori
How can I create a link with a confirmation dialog in Yii framework?
如何在 Yii 框架中创建带有确认对话框的链接?
Let's say I have
假设我有
CHtml::link('Delete',array('wsrecruiteducation/delete','id'=>$model->EducID));
how do I convert that code snippet above, into a delete link with a confirm alert before deleting the data?
在删除数据之前,如何将上面的代码片段转换为带有确认警报的删除链接?
回答by Jon
You just need to also use the last parameter of CHtml::link
:
您只需要使用 的最后一个参数CHtml::link
:
CHtml::link(
'Delete',
array('wsrecruiteducation/delete','id'=>$model->EducID),
array('confirm' => 'Are you sure?')
);
回答by Helidium
you can do something like this:
你可以这样做:
CHtml::link( 'Delete', '#', array('submit'=>array('wsrecruiteducation/delete','id'=>$model->EducID), 'params'=>('returnUrl'=>'controller/action...'), 'confirm' => 'Are you sure?') );
The returnUrl will be a post item sent with the request, make sure you make something like this in a controller with delete action:
returnUrl 将是与请求一起发送的帖子项,请确保您在具有删除操作的控制器中执行以下操作:
... if(!isset($_GET['ajax'])) $this->redirect(isset($_POST['returnUrl']) ? array($_POST['returnUrl']) : array('admin')); ...
回答by kasoft
If you wan't a delet Link with confirmation Dialog, use this
如果您不想删除带有确认对话框的链接,请使用此
echo CHtml::link("Delete", '#', array(
'submit'=>array('controller/delete', "id"=>$model->id), 'confirm' => 'Are you sure you want to delete?'));