普通网友 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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?