doudao6529
2012-03-29 19:16
浏览 60
已采纳

数据未从控制器传递到模型Opencart

I am having troubles passing data from the controller to the model in opencart(1.5.3). I have modified the 'add products' form to include a file input field, however, the results I am experiencing, I don't understand, so I'd appreciate any input, or suggestions as to a solution.

When I post the form, the data is sent to the controller, but the controller does not pass it to the model, which stops the final database query from being executed.

Im not sure if this is part of this issue, but in firebug, the post data is defined in the source list, but the field name is not defined in the parts list.

Below is an example of the code. It might be worth mentioning that I am using VQmod to add changes on the fly.

View:

      <table class="form">
        <tr>
          <td><?php echo $entry_product_pins; ?></td>
          <td><input type="file" name="product_pins" /><?php echo $tab_pins_instructions; ?>
      </td>
        </tr>
   </table>

Controller:

    if (isset($this->request->files['product_pins']['tmp_name'])) {

    $this->data['product_pins'] = file_get_contents($this->request->files['product_pins']['tmp_name']); 

                    } else {

    $this->data['product_pins'] = '';

   }

Model:

            if ( isset($this->data['product_pins']) ) {

                foreach (explode(";
", $this->data['product_pins']) as $pin) {

                $this->db->query("INSERT INTO " . DB_PREFIX . "product_pins SET pin_product_id = '" . (int)$product_id . "', pin_pin_number = '" . $this->db->escape($pin) . "'");
              }

            } else { 

// added for debugging

exit("product_pins not set"); }
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongli8722 2012-03-29 20:40
    已采纳

    Form Submission -> post data validation -> passed to model is the path in theory. What you need to do is take the pins from the $this->request->files and put it into the post data when you validate (at least that's the way I would do it), or pass the filename to the model method and extract it in the model, though that tends to get a little trickier then

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题