2012-03-19 78 views
1

我正在嘗試爲OpenCart的新聞部分創建一個全新的頁面,而且我很確定我創建了所有正確的文件,頁面呈現,但它在中間是空白的(呈現標題和頁腳罰款)。我錯過了什麼?!?OpenCart的新頁面

鏈接到命中頁:index.php?route=common/news&news_id=A_NUMBER

錶轉儲:

CREATE TABLE IF NOT EXISTS `news` (
    `id` int(255) NOT NULL AUTO_INCREMENT, 
    `user_id` int(255) NOT NULL, 
    `title` varchar(255) NOT NULL, 
    `body` longtext NOT NULL, 
    `added` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 
    `views` int(255) NOT NULL DEFAULT '0', 
    PRIMARY KEY (`id`) 
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=0 ; 

語言(news.php):

<?php 
// Text 
$_['heading_title'] = '%s'; 
?> 

控制器(news.php):

<?php 
class ControllerCommonNews extends Controller { 
    private $error = array(); 

    public function index() { 
     $this->language->load('common/news'); 

     $this->data['heading_title'] = $this->language->get('heading_title'); 

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

     $this->data['breadcrumbs'][] = array(
      'text'  => $this->language->get('text_home'), 
      'href'  => $this->url->link('common/home'),   
      'separator' => false 
     ); 

     $news_id = $_REQUEST['news_id']; 

     $this->load->model('common/news'); 

       $news_info = $this->model_common_news->getNews($news_id); 

       if ($news_info) { 
        $this->data['breadcrumbs'][] = array(
         'title'  => $news_info['title'], 
         'body'  => $news_info['body'] 
        ); 
       } 

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

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

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

M奧德爾(news.php):

<?php 
class ModelCommonNews extends Model { 

    public function getNews($news_id) { 
     $query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "news WHERE id = '" . (int)$news_id . "'"); 

     return $query->row; 
    } 

} 
?> 

視圖(news.tpl):

<?php echo $header; ?><?php echo $column_left; ?><?php echo $column_right; ?> 
<div id="content"><?php echo $content_top; ?> 
<h1 style="display: none;"><?php echo $heading_title; ?></h1> 
<?php echo $content_bottom; ?> 
</div> 
<?php echo $footer; ?> 

如果需要更多的信息請離開!任何幫助是極大的讚賞。

回答

2

您需要將一些值分配給控制器中的$ this-> data數組,並且還需要將這些變量添加到您的視圖中。

控制器

if ($news_info) { 
    $this->data['breadcrumbs'][] = array(
     'title'  => $news_info['title'], 
     'body'  => $news_info['body'] 
    ); 
    $this->data['news_title'] = $news_info['news_title']; 
    $this->data['news_text'] = $news_info['news_text'];     
} 

查看

<?php echo $header; ?><?php echo $column_left; ?><?php echo $column_right; ?> 
<div id="content"><?php echo $content_top; ?> 
<h1 style="display: none;"><?php echo $heading_title; ?></h1> 
<h2><?php echo $news_title; ?></h2> 
<div><?php echo $news_text; ?></div> 
<?php echo $content_bottom; ?> 
</div> 
<?php echo $footer; ?> 

類似的東西應該工作。

  • 聲明。我真的沒有任何使用OpenCart的經驗。我下載了源代碼並查看了一些控制器和視圖,看起來這是他們這樣做的方式。
+0

是的,我jsut開始看產品控制器,並意識到我忘了添加這些行,現在剩下的唯一問題是右側和左側列不會加載該頁面上的任何模塊。 – rackemup420 2012-03-19 19:15:13