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