Add multiple entries in another table from a module - template form?
First of all, thank you for this amazing CMS!
I'm currently using Fuel to build a site which lists music albums. So my database has an artist table, an album table and a track table.
What would be the best way to allow the user to add new tracks from the album module? It would be nice to have say 15 fields by default with the option to add more and reorder like the template form -
http://docs.getfuelcms.com/general/forms#templateI was experimenting with template form but didn't know how to hook it up to another db table. Any tutorials/info on this?
Many thanks
Comments
function form_fields($values = array(), $related = array()) { ... $CI =& get_instance(); $CI->load->model('tracks_model'); $track_values = array(); if (!empty($values['id'])) { $track_values = $CI->tracks_model->find_all_array(array('album_id' => $values['id'])); // then set the 'value' => $track_values as a template field parameter } }
See if something like that works...
Thanks again
function on_after_save($values) { parent::on_after_save($values); $new_tracklisting = $_POST['tracklisting']; //delete old tracks $this->db->where('album_id', $values['id']); $this->db->delete('tracks'); //add new tracks foreach($new_tracklisting as $track) { $track['album_id'] = $values['id']; $this->db->insert('tracks', $track); } }