How to create a link with confirmation dialog using Yii?

寵の児 提交于 2019-12-30 03:49:07

问题


How can I create a link with a confirmation dialog in Yii framework?

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?


回答1:


You just need to also use the last parameter of CHtml::link:

CHtml::link(
    'Delete',
     array('wsrecruiteducation/delete','id'=>$model->EducID),
     array('confirm' => 'Are you sure?')
);



回答2:


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:

...
if(!isset($_GET['ajax']))
     $this->redirect(isset($_POST['returnUrl']) ? array($_POST['returnUrl']) : array('admin'));
...



回答3:


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?'));


来源:https://stackoverflow.com/questions/5246361/how-to-create-a-link-with-confirmation-dialog-using-yii

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!