When inserting data in OpenCart 3.x, Uncaught Error: Call to a member function coming

When inserting data in OpenCart 3.x, Uncaught Error: Call to a member function coming

我已经使用 OpenCart 3.x 为购物车中的经销商条目创建了一个模型和控制器。提交表单时出现以下错误。

Fatal error: Uncaught Error: Call to a member function addDealer() on null in C:\xampp\htdocs\mywebsite\catalog\controller\checkout\quotation.php:27 Stack trace: #0 C:\xampp\storage\modification\system\engine\action.php(79): ControllerCheckoutQuotation->index() #1 C:\xampp\htdocs\mywebsite\catalog\controller\startup\router.php(25): Action->execute(Object(Registry)) #2 C:\xampp\storage\modification\system\engine\action.php(79): ControllerStartupRouter->index() #3 C:\xampp\htdocs\mywebsite\system\engine\router.php(67): Action->execute(Object(Registry)) #4 C:\xampp\htdocs\mywebsite\system\engine\router.php(56): Router->execute(Object(Action)) #5 C:\xampp\htdocs\mywebsite\system\framework.php(169): Router->dispatch(Object(Action), Object(Action)) #6 C:\xampp\htdocs\mywebsite\system\startup.php(104): require_once('C:\xampp\htdocs...') #7 C:\xampp\htdocs\mywebsite\index.php(19): start('catalog') #8 {main} thrown in C:\xampp\htdocs\mywebsite\catalog\controller\checkout\quotation.php on line 27

这里是模型代码,

class ModelCheckoutQuotation extends Model {
    public function addDealer($data) {
        $this->db->query("INSERT INTO " . DB_PREFIX . "dealer SET store_id = '" . (int)$this->config->get('config_store_id') . "', language_id = '" . (int)$this->config->get('config_language_id') . "', firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', ip = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "', status = 1, date_added = NOW()");

        $dealer_id = $this->db->getLastId(); 
        
        return $dealer_id;
    }
}

这是控制器代码

if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {

    $dealer_id = $this->model_checkout_quotation->addDealer($this->request->post);

    $this->response->redirect($this->url->link('checkout/quotesuccess'));
}

我把控制器放在 catalog/controller/checkout/quotation.php 里,模型放在 catalog/model/checkout/quotation.php

我不知道为什么会出现错误。没有数据库连接问题。

谢谢

您必须先在控制器文件中加载模型:

$this->load->model('checkout/quotation');

if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
        $dealer_id = $this->model_checkout_quotation->addDealer($this->request->post);
  $this->response->redirect($this->url->link('checkout/quotesuccess'));
}