I'm trying to use Grocery CRUD in my system, where I have multiple "systems" ($system_id - saved in some kind of session)
I have "Users" and "Groups" in a n-n relationship.
In users and groups i also have a "system_id".
My controller looks like this
function groups()
{
$crud = new grocery_CRUD();
$crud->set_table('groups');
$crud->where('system_id', '2');
$crud->columns('group_name');
$crud->set_relation_n_n('users', 'users_groups', 'users', 'group_id', 'user_id', 'name');
$crud->callback_before_insert(array($this,'set_system'));
$output = $crud->render();
$this->_example_output($output);
}
function users() {
$crud = new grocery_CRUD();
$crud->columns('name','number');
$crud->set_table('users');
$crud->set_relation_n_n('groups', 'users_groups', 'groups', 'user_id', 'group_id', 'group_name');
$crud->where('system_id', '2');
$crud->callback_before_insert(array($this,'set_system'));
$output = $crud->render();
$this->_example_output($output);
}
function set_system($post_array) {
if(empty($post_array['system_id'])) {
$post_array['system_id'] = $system_id;
}
return $post_array;
}
Using this it only lists the users and groups for the right system in the listing, but is there a way to show only the records with the right system_id in the n-n relation?
/Mikkel Kaas