Skip to content

Instantly share code, notes, and snippets.

@ridhotegar
Created November 20, 2020 06:48
Show Gist options
  • Save ridhotegar/8fcd4692fde3e78fbf19b32c83700833 to your computer and use it in GitHub Desktop.
Save ridhotegar/8fcd4692fde3e78fbf19b32c83700833 to your computer and use it in GitHub Desktop.
Dinamic manage menu codeigniter
public function tes()
{
$this->load->view('menu/test');
}
public function result()
{
$id_group_pengguna = '1';
$this->db->update('my_menu', array('status' => '0'), array('id_group_pengguna' => $id_group_pengguna));
foreach ($this->input->post() as $name => $value) {
if ( empty($this->M_general->get_('my_menu','*','WHERE id_group_pengguna=1 AND menu="'.$name.'"')) ) {
$data = array(
'id_group_pengguna' => $id_group_pengguna,
'menu' => $name,
'status' => $value
);
$this->db->insert('my_menu', $data);
} else {
$data = array( 'status' => $value );
$where = array(
'id_group_pengguna' => $id_group_pengguna,
'menu' => $name
);
$this->db->update('my_menu', $data, $where);
}
}
/*-------- view test ---------*/
$akses = [];
foreach ($this->db->query('SELECT * FROM my_menu')->result() as $row) {
array_push($akses, (object)[
'menu' => $row->menu,
'status' => $row->status
]);
}
// print("<pre>".print_r($akses,true)."</pre>");
$value = 'master_data';
echo $this->status($value, $akses);
}
public function status($value, $akses)
{
$status = '';
$found = array_filter($akses, function ($data) use (&$value) {return $data->menu == $value; } );
foreach ($found as $key) {$status = $key->status; } return $status;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment