在模板中获取空 - OpenCart 2.0


Getting NULL in template - OpenCart 2.0

我正在尝试用home.tpl渲染product_list.tpl文件,但它给了我NULL

控制器文件:

/controller/product/product_list.php

法典:

class ControllerProductProductList extends Controller {
    public function index() {
        $this->load->model('catalog/category');
        $this->load->model('catalog/product');
        $this->load->model('tool/image');
        $filter_data = array(
                'filter_tag'          => 'featured',
                'limit'               => 9
            );
        $data['results'] = $this->model_catalog_product->getProducts($filter_data);
        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/productlist.tpl')) {
            $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/common/productlist.tpl', $data));
        } else {
            $this->response->setOutput($this->load->view('default/template/common/productlist.tpl', $data));
        }
    }
}

要呈现的模板

/template/product/productlist.tpl

法典:

<?php var_dump($results); ?>
<h2>Product are here</h2>

然后在控制器中添加此行home.php

$data['special_mod'] = $this->load->controller('product/product_list');

并在common/home.tpl文件中打印$special_mod

问题出在/controller/product/product_list.php

方法$this->response->setOutput不仅返回值,而且将用户发送到不同的页面,而我想要的只是将productlist.tpl输出为字符串,因此我必须替换代码

if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/productlist.tpl')) {
            $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/common/productlist.tpl', $data));
        } else {
            $this->response->setOutput($this->load->view('default/template/common/productlist.tpl', $data));
        }

if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/productlist.tpl')) {
            return $this->load->view($this->config->get('config_template') . '/template/common/productlist.tpl', $data);
        } else {
            return $this->load->view('default/template/common/productlist.tpl', $data);
        }