我試圖在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();
當直接加載通過在產品控制器類的指數函數這個觀點我在我的產品視圖中回覆我的$尺寸,沒有任何東西出現。我假設在上面的函數中構建的整個視圖應該顯示出來。我錯了嗎(概率99%)?有人可以幫助我通過函數直接發佈視圖嗎?
另一個解決方案爲你粘貼size.tpl的HTML在product.tpl if條件和donot'$ this-> response-> setOutput($ this-> render());''只需從index()函數中的sizes()中獲取數據 –