[英]How to remove a record by id in Codeigniter
我正在創建一個函數來刪除Codeigniter中的記錄,但是它不能正常工作。
這是我在properties_list
按鈕
<th>
<div><a title="Delete" class="delete btn btn-sm btn-danger pull-right '.$disabled.'" data-href="'.base_url('admin/properties/del/'.$row['id']).'" data-toggle="modal" data-target="#confirm-delete"> <i class="material-icons">delete</i></a></div>
</th>
還有我的控制器上的函數DELETE Properties_php
public function del($id = 0){
$this->db->delete('ci_properties', array('propertie_id' => $id));
$this->session->set_flashdata('msg', 'Imóvel removido!');
redirect(base_url('admin/properties'));
}
嘗試這個:
<th>
<div>
<a title="Delete"
class="delete btn btn-sm btn-danger pull-right <?=$disabled?>"
data-href="<?=site_url('admin/properties/del/'.$row['id'])?>"
data-toggle="modal"
data-target="#confirm-delete">
<i class="material-icons">delete</i>
</a>
</div>
</th>
嘗試這個:
<a title="Delete" class="delete btn btn-sm btn-danger pull-right '.$disabled.'" data-href="<?php echo base_url('admin/properties/del/'.$row['id']);?>" data-toggle="modal" data-target="#confirm-delete"> <i class="material-icons">delete</i></a>
嘗試這個:
<a href="<?php
echo base_url();
?>/admin/properties/del/<?php
echo $row['id'];
?>" type="button" class="btn btn-danger" style="margin-left: 5px;">Delete</a>
定義一個類似$ url的變量,然后將其放在href標記中
<th>
<div>
<?php $url = base_url('admin/properties/del/'.$row['id']);?>
<a title="Delete" class="delete btn btn-sm btn-danger pull-right '.$disabled.'"
data-href="<?=$url?>" data-toggle="modal" data-target="#confirm-delete"> <i
class="material-icons">delete</i></a>
</div>
</th>
<th>
<div><a title="Delete" class="delete btn btn-sm btn-danger pull-right '.$disabled.'" data-href="<?php echo base_url();?>admin/properties/del/<?php echo $row['id']; ?>" data-toggle="modal" data-target="#confirm-delete"> <i class="material-icons">delete</i></a></div>
</th>
如果這給您一個錯誤,則可能是您的控制器名稱與data-href中的鏈接不匹配。
嘗試刪除以下代碼
function fnDelete(id)
{
$.ajax({
url: "<?php echo site_url('admin/properties/del'); ?>",
method: 'POST',
data: { Autoid: id },
success:function(result) {
window.location.href= "<?php echo site_url('admin/properties'); ?>";
}
});
}
public function del(){
$id=$this->input->post('Autoid');
$this->db->delete('ci_properties', array('propertie_id' => $id));
$this->session->set_flashdata('msg', 'Imóvel removido!');
redirect(base_url('admin/properties'));
}
在您的初始請求中,您將發送未處理的PHP作為url。
采用
<?= $variable;?>
<?= function();?>
在php視圖中處理鏈接內容。
我這樣解決了
<div><a title="Delete" class="delete btn btn-sm btn-danger pull-right '.$disabled.'" data-href="<?php echo base_url('admin/properties/del/'.$properties['propertie_id']);?>" data-toggle="modal" data-target="#confirm-delete"> <i class="material-icons">delete</i></a></div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.