2015-11-06 29 views
0

嘿,夥計們我試圖將數據傳遞給我的模型,但由於某種原因,我不斷收到我的模型文件中的「undefined customitem_id」。我正在測試,看看它是否會發送到模型,所以:Opencart未在模型文件中定義?

代碼如下。我的控制文件從customer.php從文件

 $data['customitem_id']= 19; 
     if(isset($this->request->post['customitem_id'])) { 
     $this->request->post['customitem_id']; 
     } 

我的代碼:

public function editCustomer($customer_id, $data) { 
     if (!isset($data['custom_field'])) { 
      $data['custom_field'] = array(); 
     } 


     $this->db->query("UPDATE " . DB_PREFIX . "customer SET customer_group_id = '" . (int)$data['customer_group_id'] . "', sales_representative = '" . $this->db->escape($data['username']) . "', firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', fax = '" . $this->db->escape($data['fax']) . "', custom_field = '" . $this->db->escape(isset($data['custom_field']) ? serialize($data['custom_field']) : '') . "', newsletter = '" . (int)$data['newsletter'] . "', status = '" . (int)$data['status'] . "', approved = '" . (int)$data['approved'] . "', safe = '" . (int)$data['safe'] . "' WHERE customer_id = '" . (int)$customer_id . "'"); 


     $this->db->query("UPDATE " . DB_PREFIX . "custom_item SET customer_id = '" . (int)$customer_id . "' WHERE customitem_id = '" . (int)$customitem_id . "'"); 

它不斷給我在模型文件中未定義的變量。我將如何去確保它發送數據?

感謝您的幫助。

回答

0

看起來你正在通過一個數組$data到你的editCustomer($customer_id, $data)對不對?從

嘗試改變這一點:您使用的變量$ customitem_id在模型中,但在你的控制器

 $this->db->query("UPDATE " . DB_PREFIX . "custom_item SET customer_id = '" . (int)$customer_id . "' WHERE customitem_id = '" . (int)$customitem_id . "'") 

$this->db->query("UPDATE " . DB_PREFIX . "custom_item SET customer_id = '" . (int)$customer_id . "' WHERE customitem_id = '" . (int)$data['customitem_id'] . "'") 

注意,我改變(int)$customitem_id(int)$data['customitem_id']

0

它是$ data ['customitem_id']。您可能只需在您的模型中將$ customitem_id更改爲$ data ['customitem_id']。