2013-08-04 108 views
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();

當直接加載通過在產品控制器類的指數函數這個觀點我在我的產品視圖中回覆我的$尺寸,沒有任何東西出現。我假設在上面的函數中構建的整個視圖應該顯示出來。我錯了嗎(概率99%)?有人可以幫助我通過函數直接發佈視圖嗎?

+0

另一個解決方案爲你粘貼size.tpl的HTML在product.tpl if條件和donot'$ this-> response-> setOutput($ this-> render());''只需從index()函數中的sizes()中獲取數據 –

回答

1

你需要做的是爲添加的路由作爲index()方法的孩子 的孩子打開/catalog/controller/product/product.php,找到這個代碼在index()方法

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

的底部,並添加你的路線,這將'product/product/sizes'sizes()方法

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

,然後在模板中,你只需要使用<?php echo $sizes; ?> WH erever你想要它去

+0

是的,你必須稱它爲一個孩子。 –

相關問題