⚠ 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

Auto the fields from database for Add View



Wilbert Santos
  • profile picture
  • Member

Posted 24 September 2013 - 05:50 AM

Hi guys, I have a question,

 

I have an idea but i don't know how to execute it in GC.

 

I just want to replicate the edit on the add view.

 

E.G.

 

i have parents and children tables.

 

parents table

-id

-first name

-last name

 

children table

-id

-first name

-last name

-parent name

 

on the parents view, i created a button, "add children" giving to the new view the id of the parent via GET.

something like, children/add/14 the 14 is the id of the parent on the table.

 

using the 14(the id of the  parent), i will query the database, get the first name and the last name of the parent, and i need to set those data on the fields on the add of the view on the children.

 

so on the add view of the children the last name and the parent name will automatically have values from database....

 

 

did you guys get the idea? i need some help.. im searching the forum but its kinda hard to find exactly what im searching for.

 

thanks in advance!


briggers
  • profile picture
  • Member

Posted 24 September 2013 - 09:03 AM

Hi,

It's not too difficult.

 

  • Make sure that you have a "parent_id" field in your child table
  • Set up 2 GC controllers, one for parents one for children
  • In the parents controller use "add_action(Add/edit children)" to link to the children controller passing the parent _id as a parameter
  • In the children controller have a "where" clause to select only children of the selected parent
  • In the children controller have a "get" method to get the parents names from the parent table
  • in the children controller have 2 hidden fields, parents_first_name & parents_last_name and give them the values from the "get"

Hope that helps


davidoster
  • profile picture
  • Member

Posted 24 September 2013 - 09:32 AM

[member=briggers] nice outline!

Just a quick note, this can be done also on the same controller via different controller functions, unless you meant it like this :)


briggers
  • profile picture
  • Member

Posted 24 September 2013 - 11:06 AM

David,

 

Just a personal preference for keeping controllers short and specific to the purpose - so in this case one controller for working with parents and one for children so that when maintaining the system n years later I know where to look and don't need a note/reminder that children are processed in parents.

 

Thanks for the likes.

 

Richard 


davidoster
  • profile picture
  • Member

Posted 24 September 2013 - 12:39 PM

Very true [member=briggers].

Thanks for clarifying this!