0

我正在尝试渲染product_list.tpl文件,home.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');

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

4

1 回答 1

0

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

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

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);
        }
于 2015-03-17T12:19:02.677 回答