⚠ 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

Passing info to a custom model?



Dale
  • profile picture
  • Member

Posted 20 April 2013 - 12:50 PM

I've created a custom model and I want to pass parameters to it.

 

I can do it by putting in a variable (current a static one) that I can set, but to do this I've had to modify GC to include a get_model method.

 

Is there a better way to do this?

 

thanks,


davidoster
  • profile picture
  • Member

Posted 21 April 2013 - 00:36 AM

I am not sure I understand exactly where the problem is.

Usually we would do something like this, /topic/1578-filter-relation-using-third-table/#entry6865


Dale
  • profile picture
  • Member

Posted 21 April 2013 - 08:18 AM

I wanted to do a join across several tables and the documentation says the way to do it is to place the query inside the model.

 

If you can simply call the query from outside and build it up into data for GC, and have GC update the values then that's interesting. Most of what I've read here says "no support for joins (yet)".

 

My situation is that I have 3 tables, Company, Location, Other.

 

I need managers to be able to edit Other, have managers select a location, and admins to select a location and company.

Managers are within a Company, so that has to be selected, but not shown to them.


davidoster
  • profile picture
  • Member

Posted 21 April 2013 - 09:19 AM

You can have something like this,

 

function my_controller
{
 $crud->set_table('other');
 if($user->is_manager())
 {
  $crud->fields(...); // all except company
  $crud->columns(...); // everything
  $crud->where('company',$user->company);
  $crud->callback_before_insert(array($this, 'mycallback');

 }
}


function mycallback($post_array)
{
 $post_array['company'] = $user->company;
 return $post_array;
}

 

 

But I am still unsure how you differentiate between records that an admin has inserted from a manager.

Hence, do managers see the records added by the admins, if not then you need to put something more in your logic in order to support this.

If that's not the case then your case is simple and it doesn't need any complex joins or something similar.


Dale
  • profile picture
  • Member

Posted 22 April 2013 - 12:48 PM

You can have something like this,

 

function my_controller
{
 $crud->set_table('other');
 if($user->is_manager())
 {
  $crud->fields(...); // all except company
  $crud->columns(...); // everything
  $crud->where('company',$user->company);
  $crud->callback_before_insert(array($this, 'mycallback');

 }
}


function mycallback($post_array)
{
 $post_array['company'] = $user->company;
 return $post_array;
}

 

 

But I am still unsure how you differentiate between records that an admin has inserted from a manager.

Hence, do managers see the records added by the admins, if not then you need to put something more in your logic in order to support this.

If that's not the case then your case is simple and it doesn't need any complex joins or something similar.

 

 

-----------------------------------------------

The admin sees a superset of values - the manager sees only those locations and others that are relevant to the company they are in.

 

Managers will see any records added by admin for their company.

In your solution you have set_table ('other'), but the where clause introduces another table (company). How does that table end up in the from clause (or is that a standard part of CI?)

 

Also how do you filter for the chain of locations that are connected to companies?

 

thanks,


davidoster
  • profile picture
  • Member

Posted 22 April 2013 - 13:50 PM

Have you tried the above code?