如何在Opencart中加载自定义模型

时间:2014-03-17 07:18:51

标签: php classloader opencart

我在Opencart中创建了一个自定义模块。

详情:

控制器:admin / controller / custom / block.php中名为block.php的文件

查看:admin / view / template / custom / block.tpl中名为block.tpl的文件

模型:admin / model / custom / block.php中名为block.php的文件

我已成功配置权限。

enter image description here

当我在Controller中加载此模型时,我收到以下错误..

Fatal error: Call to a member function load() on a non-object in F:\xampp\htdocs\shirtrecipe\admin\controller\custom\block.php on line 11

控制器代码:

<?php

class ControllerCustomBlock extends Controller
{
public function index() {


    $this->language->load('custom/block');

    $this->model->load('custom/block'); /* doesnt load this model */

    $this->data['breadcrumbs'] = array();
            ...
            ...

型号代码:

<?php

class ModelCustomBlock extends Model
{

public function get_demo_block() {

    $sql = "select demo_block_img from oc_block where id=1";
    $query = $this->db->query($sql);

    return $query->row;

}


}

1 个答案:

答案 0 :(得分:2)

更改:

$this->model->load('custom/block');

要:

$this->load->model('custom/block');

度过美好的一天!!