我在CodeIgniter中编辑和删除数据时遇到问题。 我尝试过一些可选项,但它不起作用。有人能帮助我吗?
这里我附上了控制器和模型。
kode_bahan_baku = kbb
nama_bahan_baku = hps
edit bahan baku = edit_dbb
delete bahan baku = delete_dbb
<?php defined('BASEPATH') OR exit('No direct script access allowed');
Class Model_data extends CI_Model{
public function __construct(){
parent::__construct();
}
// Data Bahan Baku
public function set_dbb(){
$data = array(
'bb_code' => $this->input->post('kbb'),
'bb_price' => $this->input->post('hps')
);
return $this->db->insert('data_bahan_baku',$data);
}
public function get_dbb(){
$query = "select * from data_bahan_baku";
$sql = $this->db->query($query);
return $result = $sql->result();
}
public function edit_dbb(){
$data = array(
'bb_code' => $this->input->post('kbb'),
'bb_price' => $this->input->post('hps')
);
$this->db->where('kbb',$id);
$edit = $this->db->update('data_bahan_baku',$data);
return $edit;
}
public function delete_dbb($id){
$data = array(
'bb_code' => $this->input->post('kbb'),
'bb_price' => $this->input->post('hps')
);
$this->db->where('kbb',$id);
return $this->db->delete('data_bahan_baku');
}
<?php defined('BASEPATH') OR exit('No direct script access allowed');
Class Control_data extends CI_Controller{
public function __construct(){
parent::__construct();
$this->load->model("model_data");
}
// Entry Data
/*Input Data Bahan Baku*/
public function data_bahan_baku(){
$data = array();
$data['title'] = "Data Bahan Baku";
$data['result'] = $this->model_data->get_dbb();
$this->form_validation->set_rules('kbb','Kode Bahan Baku','required');
$this->form_validation->set_rules('hps','Harga Per Satuan','required');
if($this->form_validation->run() == FALSE){
$this->load->view('data/data_bahan_baku',$data);
}else{
$this->model_data->set_dbb();
$this->load->view('data/data_bahan_baku',$data);
}
}
/*Edit Data Bahan Baku*/
public function edit_data_bahan_baku($id){
$this->model_data->edit_dbb($id);
}
/*Delete Data Bahan Baku*/
public function delete_data_bahan_baku($id){
$this->model_data->delete_dbb($id);
redirect('control_data/data_bahan_baku');
}