我正在尝试以相同的形式更新2个表frm_data_aset和frm_monitor。在frm_data_aset中有列lokasi_aset而在frm_monitor中有列lokasi_monitor,我希望两列都插入相同的值。
当我尝试运行此操作时,我在此输入代码我收到错误:
严重性:注意 消息:未定义的属性:Data_aset :: $ M_monitor
文件名:controllers / Data_aset.php
行号:120
如何在codeigniter中更新2个表?
我在控制器上的功能
{
$this->_rules();
if ($this->form_validation->run() == FALSE) {
$this->create();
} else {
$data = array(
'pengguna_aset' => $this->input->post('pengguna_aset',TRUE),
'tglkirim_aset' => tanggal_db ($this->input->post('tglkirim_aset',TRUE)),
'lokasi_aset' => $this->input->post('lokasi_aset',TRUE),
'komputer_aset' => $this->input->post('komputer_aset',TRUE),
'monitor_aset' => $this->input->post('monitor_aset',TRUE),
'keyboard_aset' => $this->input->post('keyboard_aset',TRUE),
'mouse_aset' => $this->input->post('mouse_aset',TRUE),
'printer_aset' => $this->input->post('printer_aset',TRUE),
'scanner_aset' => $this->input->post('scanner_aset',TRUE),
'stabilizer_aset' => $this->input->post('stabilizer_aset',TRUE),
'ups_aset' => $this->input->post('ups_aset',TRUE),
'finger_aset' => $this->input->post('finger_aset',TRUE),
'switch_aset' => $this->input->post('switch_aset',TRUE),
'ket_aset' => $this->input->post('ket_aset',TRUE),
'user_modify_aset' => $this->session->userdata('user_id',TRUE),
'date_modify_aset' => $this->input->post('date_modify_aset',TRUE),
);
$data2 = array(
'lokasi_aset' => $this->input->post('lokasi_monitor', TRUE),
);
$this->M_data_aset->insert($data);
$this->M_monitor->insert('frm_monitor;$data2');
$this->session->set_flashdata('message', 'Create Record Success');
redirect(site_url('data_aset'));
}
}
但是,如果我只是更新单个表,它正在工作,没有此代码
$data2 = array(
'lokasi_aset' => $this->input->post('lokasi_monitor', TRUE),
);
$this->M_monitor->insert('frm_monitor;$data2');
答案 0 :(得分:0)
$this->M_monitor->insert('frm_monitor;$data2');
应该是:
$this->M_monitor->insert('frm_monitor', $data2);
假设您的insert
函数执行类似的操作:
function insert($form, $data) { ... }
此外,根据您的数据库架构,您的字段不能为NULL:
$data2 = array(
'lokasi_aset' => !is_null($this->input->post('lokasi_monitor', TRUE)) ? $this->input->post('lokasi_monitor', TRUE) : ''
);