Here is the code for a CRUD that shows only items that have a 'status' of 'red':
try{
$crud = new grocery_CRUD();
$crud->set_theme('datatables');
$crud->where('status', 'red');
$crud->set_table('items');
//add custom action that will call the change the change_status function
$crud->add_action('Move', '', '','', array($this,'change_status'));
//stop status from showing up in the field lists
$crud->unset_fields('status');
$this->output($output);
}catch(Exception $e){
show_error($e->getMessage().' --- '.$e->getTraceAsString());
}
Here is the change_status function that changes the status of the item from red to green and then goes to a new page that shows only green items.
public function change_status($primary_key)
{
$update_status = array(
"status" => "green"
);
$this->db->where('id', $primary_key);
$this->db->update('items', $update_status);
return site_url('showitems/green');
}
When clicking the 'move' button the status of the item changes from red to green and the page changes to show all green items. However when clicking on the edit button if I press 'update' or 'cancel' (even without actually changing anything) and then go back to the list (the red list) I see that the item is no longer in the red list - its status has been changed to green and is now in the green list.
Is there any reason for this, or any workaround to prevent this behaviour from happening?