⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Grocery CRUD with multiple "logins"



mikkelkaas
  • profile picture
  • Member

Posted 21 March 2012 - 12:30 PM

Hi

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

mikkelkaas
  • profile picture
  • Member

Posted 21 March 2012 - 12:31 PM

And how do I hide system_id on the add/update page?

mikkelkaas
  • profile picture
  • Member

Posted 22 March 2012 - 09:48 AM

Solved the last question using $crud->fields('group_name', 'users'); - But i'm still having problems with the first question

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 29 March 2012 - 06:50 AM


$crud->change_field_type('system_id', 'hidden', 2);