我无法在codeigniter中删除用户,当我点击链接删除时,它无法正常工作。 这是关于tutlus的系列文章:在CodeIgniter中构建CMS。
链接删除:/ admin / user / delete / 3
控制器:
class User extends Admin_Controller{
public function __construct() {
parent::__construct();
}
public function delete() {
$this->user_m->delete($id);
redirect('admin/user');
}
}
型号:
class User_M extends MY_Model {
protected $_table_name = 'users';
protected $_order_by = 'name';
function __construct() {
parent::__construct();
}
}
MY_Model:
class MY_Model extends CI_Model {
protected $_table_name = '';
protected $_primary_key = 'id';
protected $_primary_filter = 'intval';
protected $_order_by = '';
public $rules = array();
protected $_timestamps = FALSE;
function __construct() {
parent::__construct();
}
public function delete($id){
$filter = $this->_primary_filter;
$id = $filter($id);
if(!$id) {
return FALSE;
}
$this->db->where($this->_primary_key, $id);
$this->db->limit(1);
$this->db->delete($this->_table_name);
}
}
答案 0 :(得分:2)
尝试将您从网址获得的$id
传递给
public function delete($id) {
$this->user_m->delete($id);
redirect('admin/user');
}
答案 1 :(得分:0)
在用户控制器中传递您的ID
public function delete($id)
{
$this->user_m->delete($id);
redirect('admin/user');
}
答案 2 :(得分:0)
您必须从网址
获取ID public function delete() {
$this->load->helper('url');
$id= $this->uri->segment(3) ;
$this->user_m->delete($id);
redirect('admin/user');
}