[我想使用两个模型从两个表中删除数据,但不能这样做。我正在使用以下代码。帮助我解决这个问题]
public function delete_all_info_employee($id) {
// ************* Delete into Employee Table
$this->employee_model->_table_name = "tbl_employee"; // table name
$this->employee_model->_primary_key = "employee_id"; // $id
$this->employee_model->delete($id);
$this->expense_model->_table_name = "tbl_expense"; // table name
$this->expense_model->_primary_key = "expense_id"; // $id
$this->expense_model->delete($id);
$type = "success";}
答案 0 :(得分:1)
首先检查你已经在codeigniter \ application \ config \ autoload.php中加载了数据库
$autoload['libraries'] = array('database');
您的模型方法
public function delete_all_info_employee($id) {
// ************* Delete into Employee Table
$this->db->where('employee_id', $id);
$this->db->delete('tbl_employee');
$this->db->where('expense_id', $id);
$this->db->delete('tbl_expense');
return "success";
}