簡體   English   中英

Opencart在模型文件中未定義?

[英]Opencart Undefined in model file?

大家好,我試圖將數據傳遞給我的模型,但是由於某種原因,我在模型文件中始終收到“未定義的customitem_id”。 我正在測試,看它是否還會發送給模型,以便:

代碼如下。 我的controller文件來自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 . "'");

它總是在模型文件中給我一個未定義的變量。 我將如何確保它發送數據?

謝謝你的幫助。

看起來您要將數組$data傳遞到editCustomer($customer_id, $data)對嗎?

嘗試從以下方式進行更改:

        $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']

您在模型中使用變量$ customitem_id,但在控制器中,變量為$ data ['customitem_id']。 您可能只需要在模型中將$ customitem_id更改為$ data ['customitem_id']。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM