Codeigniter set_value()具有动态多维数组输入

OK, I am generating a form which is pre-populated with existing values from the db:

View:

    <tr>
      <td><input name="set[<?php echo $cur_set['id']; ?>][order]" value="<?php echo $cur_set['wo_order']; ?>">
          <input type="hidden" name="set[<?php echo $cur_set['id']; ?>][ex_id]" value="<?php echo $cur_set['ex_id']; ?>"></td>
      <td><input name="set[<?php echo $cur_set['id']; ?>][weight]" value="<?php echo $cur_set['weight']; ?>"></td>
      <td><input name="set[<?php echo $cur_set['id']; ?>][reps]" value="<?php echo $cur_set['reps']; ?>"></td>
    </tr>

Example output:

    <tr>
      <td><input name="set[3][order]" value="1">
          <input type="hidden" name="set[3][ex_id]" value="1"></td>
      <td><input name="set[3][weight]" value="50.00"></td>
      <td><input name="set[3][reps]" value="5"></td>
    </tr>

So I have a range of these <tr>s each can have a unique 'id' but all have the same number of secondary indices [order], [ex_id], [weight] and [reps].

I cannot figure out 2 things:

  1. How to apply the set_value() syntax when I don't know what the [id] is going to be.
  2. How to set validation rules on the form. I have tried:

    $this->form_validation->set_rules('set[][order]', 'Sets', 'required');
    

but it doesn't seem to work as set[][order] is not found...can I put some sort of wildcard in there? Like set[*][order]?

Thanks in advance.

Jon

In the controller, where you fetch the data and store it in a variable (I'll call it $data), do this:

$data = $this->MODEL_NAME->METHOD_NAME();

foreach($data as $set){
    $this->form_validation->set_rules("set[{$set['id']}][order]");
    $this->form_validation->set_rules("set[{$set['id']}][weight]");
    etc...
}