0

当在 opencart 中选择产品时,我试图在选项卡上获取尺寸图表。为此,我有一个如下所示的模型

class ModelCatalogSizes extends Model {     
    public function getSizes()
    {
        $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "sizes ORDER BY id");
        return $query->rows;
    }
}

我将视图视为相同的模板,它只是一个带有值作为输入单选选项的 html 表。

在我的产品控制器类中,我有如下功能

public function sizes()
{
    $this->language->load('product/product');

    $this->load->model('catalog/sizes');

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

    $results = $this->model_catalog_sizes->getSizes();

    foreach ($results as $result) {
        $this->data['sizes'][] = array(
            'type'       => ucfirst($result['type']),
            'coat'       => $result['coat'],
            'chest'      => $result['chest'],
            'cverarm'    => $result['overarm'],
            'waist'      => $result['waist'],
            'hip'        => $result['hip'],
            'inseam'     => $result['inseam'],
            'neck'       => $result['neck'],
            'sleeve'     => $result['sleeve'],
            'height'     => $result['height'],
            'weightLb'   => $result['weightLb'],
            'weightKg'   => $result['weightKg'],
        );
    }

    if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/sizes.tpl')) {
        $this->template = $this->config->get('config_template') . '/template/product/sizes.tpl';
    } else {
        $this->template = 'default/template/product/sizes.tpl';
    }

    $this->response->setOutput($this->render());
}

现在我试图通过产品控制器类中的索引函数直接加载这个视图$this->data['size'] = $this->sizes();

当我在我的产品视图中回显我的 $size 时,什么也没有出现。我认为应该显示在上面的函数中构建的整个视图。我错了吗(概率 99%)?有人可以帮助我通过函数直接发布视图吗?

4

1 回答 1

1

What you need to do is add the route for that as a child of the index() method's children Open /catalog/controller/product/product.php and find this code at the bottom of the index() method

$this->children = array(
    'common/column_left',
    'common/column_right',
    'common/content_top',
    'common/content_bottom',
    'common/footer',
    'common/header'
);

and add your route, which would be 'product/product/sizes' for your sizes() method

$this->children = array(
    'common/column_left',
    'common/column_right',
    'common/content_top',
    'common/content_bottom',
    'common/footer',
    'common/header',
    'product/product/sizes'
);

And then in your template, you just need to use <?php echo $sizes; ?> wherever you want it to go

于 2013-08-04T18:02:52.373 回答