Hello All im stuck in a weird position.
I have a table with the columns. id_acces, id_user, id_menu, has_access (boolean)
im basically have a form with a list of checkboxes and id numbers to allow access to parts of a page to a specific user. Basically i need to update the table with either has access or not and if there is no entry for the user regarding to pages chosen to create a new entry in the table. So my array im getting back looks like this
Array
(
[AdminMenu] => Array
(
[id_user] => 1
[id_menu] => Array
(
[4] => enabled
[21] => enabled
[22] => enabled
[23] => enabled
[24] => enabled
[1] => enabled
[5] => enabled
[25] => enabled
[26] => enabled
[6] => enabled
[7] => enabled
[29] => enabled
[8] => enabled
[30] => enabled
[31] => enabled
[32] => enabled
[33] => enabled
[34] => enabled
[35] => enabled
[36] => enabled
[37] => enabled
[38] => enabled
[39] => enabled
[40] => enabled
[41] => enabled
[60] => enabled
[2] => enabled
[10] => enabled
[11] => enabled
[12] => enabled
[13] => enabled
[14] => enabled
[15] => enabled
[16] => enabled
[17] => enabled
[18] => enabled
[9] => enabled
[3] => enabled
[19] => enabled
[20] => enabled
)
)
)
The key is the id_menu and the value is just if the checkbox is checked or not.
can someone please tell me how i can user this array to do a insert or update in cake php to my table. Im currently looping through the array as $key=>$value and running a query against the table for the key to exist. if it exists then i need to run a update query if not then i need to do a insert query for that specific page or id_menu. Please help
foreach($this->data['AdminMenu']['id_menu'] as $key=>$value) {
$check = select against the table where the id_menu = $key
if($key = $check[0]['AdminAccess']['id_menu']) {
$this->AdminAcess->id_menu=$key;
$this->AdminAccess->id_user=$user_id;
$this->AdminAccess->set('has_access', 't');
$this->AdminAccess->save();
} else {
$this->AdminAcess->id_menu=$key;
$this->AdminAccess->id_user=$user_id;
$this->AdminAccess->saveField('has_access', 'false');
}
}
im sure there is got to be a easier way then this loop. Also how do i do the insert or update. this isnt even doing a insert or update either way