⚠ 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

more insert in one table by



ocrama

ocrama
  • profile picture
  • Member

Posted 01 October 2013 - 13:29 PM

hi all, i'm new to this forum. I'm also new to grocery crud and i'm stuck in a problem:

 

i have the tipically tables: users, users_groups, groups

 

In the insert form you can select one or more groups for the single user.

 

How can i insert (or update) the table users_groups?

 

thanks


davidoster

davidoster
  • profile picture
  • Member

Posted 02 October 2013 - 08:22 AM

Hello and welcome to the forums [member=ocrama].

If we respond the Grocery CRUD way I would suggest,

on the controller function that shows the users table add the following code:

$crud->callback_after_insert(array($this, 'update_user_after_insert'));

 

And then as you imagine use a similar function as the function log_user_after_insert($post_array,$primary_key)

that is presented to the example.

Similarly you can do it for callback_after_update.


ocrama

ocrama
  • profile picture
  • Member

Posted 02 October 2013 - 09:44 AM

Thank you very much for reply.

I've tried this code on my function:

$crud->callback_after_insert(array($this, 'profile_user_after_insert'));

and this is the callback implementation:

    function profile_user_after_insert($post_array,$primary_key)
    {
        $user_info = array(
            "user_id" => $primary_key,
            "group_id" => '1'            
        );        
        $this->db->insert('users_profile',$user_info);
        return true;
    }

but it seems doesn't work. I've tried 

$crud->callback_insert

before, and this work. But when i add the callback_after_insert it doesn't work.

any suggestion please?

thanks


ocrama

ocrama
  • profile picture
  • Member

Posted 02 October 2013 - 10:13 AM

the problem is:

 

i have a table called users, a table called users_profile and a table called profile.

In the 

$crud->callback_insert

I perform an insert in the table users and it works fine

 

in the 

$crud->callback_after_insert

i should perform an insert in users_profile

but it don't work.

Maybe the problem is the $primary_key? how can i give that value to the function?