Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Many to Many Relation and Multi Select
  • Hi, I have two models, 'Group' and 'Section'. There are 5 sections, and each group can have any combination of sections. So, I've successfully set up a relationship with $_has_many and $_many_many and a joining table. I tried implementing a multiselect on my form using a similar technique to other one-to-many relations, but I'm a bit puzzled as to how to save and repopulate properly. I've managed to save the relation once using the example from the Docs page, but it wouldn't re-save! $sections = Input::post('sections');
    $count=0;
    foreach ($sections as $section_id) {
    $group->sections[$count] = Model_Section::find($section_id);
    $count++;
    } I've populated the select like so: $selected = $group->sections;
    $selected_sections = array();
    foreach ($selected as $section) {
    $selected_sections[] = $section->id;
    }
    $view->set_global('selected',$selected_sections); And the form: <?php echo Form::select('sections[]', $selected_sections, $sections, array('class' => 'span6','multiple'=>'multiple')); ?> If someone could point me to an example that'd be great. Not sure if there's a much easier way that I'm missing? Sorry about formatting - my editor doesn't seem to be working. Thanks, Rich

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!