Hey.
i've created a module with some tables. one of them (entries) has an second table (entries_meta) for additional infos.
in the method form_fields of the entries model i need those fields from the entries_meta. how can i do that?
create a own model for entries_meta? or just create a loop and add those fields to the $fields array and save them with the the on_after_save hook? (if i should add them to the $fields array, can i transform the db-fields automatically into form elements? (with your form_helper)
what's your opinion about that?
Comments
i need then a short advise:
how can i include the form_fields from one module into another?
$fields = array(); $meta_fields = $CI->meta_model->form_fields(); array_push($fields, $meta_fields);
and to save?
$CI->meta_model->save();
$CI->load->model('meta_model');
but how do i set the ID?
entries_table: id => auto_increment title => varchar entries_meta_table: id => auto_increment entryID => int
how do tell the meta_model the recent entry ID?
function form_fields($values = array()) { $fields = parent::form_fields($values); $CI =& get_instance(); $CI->load->model('meta_model'); $meta_values = array(); if (isset($values['id']) { $meta_values = $CI->meta_model->find_one_array(array('entryID' => $values['id'])); } $meta_fields = $CI->meta_model->form_fields($meta_values); $fields = array_push($fields, $meta_fields); /*..... ANY OTHER LOGIC LIKE FIELD ORDERING, ETC ....*/ return $fields; }
thank you so much for your time. actually, i am already over that.
i stuck at the save part.
let me show you my example:
my entry_model:
- id
- first_name
- last_name
- etc.
my entry_meta_model:
- id
- entry_id (the id from entry_model)
- country
- zip
- etc.
in my entry_model in on_after_save :
$CI->meta_model->save();
but i have logical problems with my meta_meta_model. who can i tell that model to update the right entry_id - which came must be the ID from entry_model?
Things i noticed for my entry_meta_model (correct?):
$key_field = entry_id (?)