Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a link with confirmation dialog using Yii?

Tags:

php

yii

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?

like image 534
sasori Avatar asked Mar 09 '11 13:03

sasori


2 Answers

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?')
);
like image 70
Jon Avatar answered Oct 13 '22 21:10

Jon


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'));
...
like image 31
Helidium Avatar answered Oct 13 '22 19:10

Helidium