public function addData()
{
$this->db->trans_begin();
try{
if ($this->form_validation->run() == TRUE){
$menu = array(
'menu_name' => $label,
'url' => $path,
'parent_id' => $parent,
'icon' => $icon,
'status' => 1,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
);
$this->db->insert('tbl_menu', $menu);
$last_menu_id = $this->db->insert_id();
foreach ($roles as $key => $value) {
$permission = array(
'role_id' => $value,
'menu_id' => $last_menu_id,
'status' => 1,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s')
);
$this->db->insert('tbl_permissions', $permission);
}
$this->session->set_flashdata('success','Menu Added Successfully...!!!');
}else{
$this->session->set_flashdata('error','You have to fill fields...!!!');
}
$this->db->trans_commit();
redirect('menu/add');
}catch(Exception $e){
$this->db->trans_rollback();
$this->session->set_flashdata('error',$e->getMessage());
redirect('menu/add');
}
}
你好,伙计们,
在这里,第二个表名称不正确。但是当我运行代码时,它不会返回错误&没有回滚(它将数据插入第一个表格)。问题是什么??
答案 0 :(得分:0)
{{1}}
最后我试着这样做了。工作。删除了“try-catch”