2012-03-19 8 views
1

Я пытаюсь создать совершенно новую страницу для OpenCart для раздела новостей, и я был уверен, что создал все нужные файлы, страница отображает, но она пуста посередине (отображает заголовок и нижний колонтитул прекрасный). Что я упустил?!?Новая страница для OpenCart

Ссылка на Hit Страница: index.php?route=common/news&news_id=A_NUMBER

Таблица Dump:

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'; 
?> 

Controller (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; 
    } 

} 
?> 

View (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

Да, я начал изучать контроллер продукта и понял, что забыл добавить в эти строки, теперь остается только проблема, заключающаяся в том, что правый и левый столбцы не загружают модули на этой странице. – rackemup420

Смежные вопросы