0
我有麻烦从控制器传递数据到opencart模型(1.5.3)。我修改了“添加产品”表单以包含文件输入字段,但是,我所遇到的结果我不明白,因此我会很感激任何意见或解决方案的建议。数据没有从控制器传递到模型Opencart
当我发布表单时,数据被发送到控制器,但控制器不会将它传递给模型,从而停止执行最终的数据库查询。
我不确定这是否是这个问题的一部分,但在萤火虫中,发布数据是在源列表中定义的,但字段名称未在零件列表中定义。
下面是一个代码示例。值得一提的是,我正在使用VQmod来即时添加更改。
查看:
<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>
控制器:
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'] = '';
}
型号:
if (isset($this->data['product_pins'])) {
foreach (explode(";\n", $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"); }
这里不清楚你在做什么,如果你试图获取数据视图或模型完全?当数据从产品表单传递给模型时,它是传递给模型的$ this-> request-> post。 $ this-> request-> files不是 – 2012-03-29 19:43:13
@JayGilford好吧,我需要将一个cvs文件引入到数据库(它自己的表)中,并将它与一个产品ID相关联。我在插入产品表单中创建了这个模块,以便可以轻松实现这种关联(编辑/添加产品时)。在我的想法中,表单数据通过控制器进入$ this-> data数组,然后进行验证,然后将其传递给模型..这不正确? – Lea 2012-03-29 19:58:40