codeigniter - 在 opencart 中加载和使用模型

标签 codeigniter opencart

据我所知,开放式购物车基于 CodeIgniter,但在 CodeIgniter 中加载和使用模型,您可以执行以下操作

$this->load->model('Model_name');

$this->Model_name->function();

在 OpenCart 你做这样的事情
$this->load->model('catalog/product');
$this->model_catalog_product->getTotalProducts()

这是如何工作的,“model_catalog_product”从哪里来?

除了论坛之外,他们似乎还有 0 个开发人员文档。

最佳答案

OpenCart 的加载器类 seems to be inspired由 CodeIgniter 编写,但并非基于它。您可以查看 OpenCart 的源代码,参见文件 system/engine/loader.php (第 39 行)。

public function model($model) {
    $file  = DIR_APPLICATION . 'model/' . $model . '.php';
    $class = 'Model' . preg_replace('/[^a-zA-Z0-9]/', '', $model);                      

    if (file_exists($file)) {
        include_once($file);

        // Right here. Replaces slash by underscore.
        $this->registry->set('model_' . str_replace('/', '_', $model), new $class($this->registry));
    } else {
        trigger_error('Error: Could not load model ' . $model . '!');
        exit();                 
    }
}

您可以清楚地看到它用下划线替换斜线并附加 'model_'在模型名称之前。这就是为什么你最终会得到 model_catalog_product .

关于codeigniter - 在 opencart 中加载和使用模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13464415/

相关文章:

php - 代码点火器 MY_Controller : is it only possible to extend core once?

php - 为什么这个 'case' 查询在 codeigniter 中不返回 'true' 或 'false'

php - 如何将PHP imagecopymerge函数创建的图像存储在mysql数据库中

php - 将 Open Cart 1.5.6.1 升级到 1.5.6.4 后文件管理器出现 500 Internal Server Error

php - OpenCart 配置类如何工作?

php - jquery ajax 未创建 session

mysql - 如何使用mamp将数据库与codeigniter连接

javascript - 如何将 Tawk 聊天嵌入到 OpenCart 3

CSS 和 OpenCart

php - 拆分分隔文本并与另一个字段配对