我正在學習 CodeIgniter 3,我想在洗掉資料庫表中的一行之前添加一個確認對話框。我做了洗掉功能,但不知道如何使用 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]);
}
uj5u.com熱心網友回復:
這是一個簡單的集成,嘗試讓我知道
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>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/370484.html
標籤:php 代码点火器 codeigniter-3 甜蜜警报2
上一篇:保存表格后如何將檔案上傳到檔案夾
