如何在 CodeIgniter 3 中使用 SweetAlert2 添加确认对话框?
How to add a confirm dialog box using SweetAlert2 in CodeIgniter 3?
我正在学习 CodeIgniter 3,我想在删除数据库中的行之前添加一个确认对话框 table。我做了删除功能,但不知道如何使用 SweetAlert2 添加确认对话框。
代码在视图中
<td><a href="<?php echo base_url('index.php/admin/deletestaff/' . $row->StaffUserName) ?>"
class="btn btn-danger btn-sm">Delete</a></td>
控制器中的代码
public function deleteStaff($staff)
{
$this->load->model('Staff_Model');
$this->Staff_Model->deleteStaff($staff);
redirect(base_url('index.php/admin/viewstaff'));
}
模型中的代码
function deleteStaff($staff)
{
return $this->db->delete('staff', ['StaffUserName' => $staff]);
}
这是一个简单的集成,试试让我知道
function confirm(staffname){
Swal.fire({
title: 'Do you want to save the changes?',
showDenyButton: true,
showCancelButton: true,
confirmButtonText: 'Save',
denyButtonText: `Don't save`,
}).then((result) => {
/* Read more about isConfirmed, isDenied below */
if (result.isConfirmed) {
window.location.href = "<?php echo base_url('index.php/admin/deletestaff/' ;?>" + staffname;
Swal.fire('Saved!', '', 'success')
} else if (result.isDenied) {
Swal.fire('Changes are not saved', '', 'info')
}
});
}
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<a id="mylink" href="javascript:;" class="btn btn-danger btn-sm" onclick="return confirm('<?php echo $row->StaffUserName;?>');">Delete</a>
我正在学习 CodeIgniter 3,我想在删除数据库中的行之前添加一个确认对话框 table。我做了删除功能,但不知道如何使用 SweetAlert2 添加确认对话框。
代码在视图中
<td><a href="<?php echo base_url('index.php/admin/deletestaff/' . $row->StaffUserName) ?>"
class="btn btn-danger btn-sm">Delete</a></td>
控制器中的代码
public function deleteStaff($staff)
{
$this->load->model('Staff_Model');
$this->Staff_Model->deleteStaff($staff);
redirect(base_url('index.php/admin/viewstaff'));
}
模型中的代码
function deleteStaff($staff)
{
return $this->db->delete('staff', ['StaffUserName' => $staff]);
}
这是一个简单的集成,试试让我知道
function confirm(staffname){
Swal.fire({
title: 'Do you want to save the changes?',
showDenyButton: true,
showCancelButton: true,
confirmButtonText: 'Save',
denyButtonText: `Don't save`,
}).then((result) => {
/* Read more about isConfirmed, isDenied below */
if (result.isConfirmed) {
window.location.href = "<?php echo base_url('index.php/admin/deletestaff/' ;?>" + staffname;
Swal.fire('Saved!', '', 'success')
} else if (result.isDenied) {
Swal.fire('Changes are not saved', '', 'info')
}
});
}
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<a id="mylink" href="javascript:;" class="btn btn-danger btn-sm" onclick="return confirm('<?php echo $row->StaffUserName;?>');">Delete</a>