Deepu Sasidharan
Deepu Sasidharan

Reputation: 5309

How to create new page in Opencart

I am using Opencart Version 2.0.3.1.

I have to create new page in Opencart. But I don't know how to start. So I followed the given link http://forum.opencart.com/viewtopic.php?t=6253 to create custom page.

But I got the error

Fatal error: Cannot access private property Document::$title in C:\wamp\www\opencart\catalog\controller\custom\service.php on line 6

As mentioned in the link,I created three files are:

catalog/controller/custom/service.php

class ControllerCustomService extends Controller {
   public function index() {
      $this->language->load('custom/service');

      $this->document->title          = $this->language->get('heading_title');


      $this->document->breadcrumbs = array();

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

      $url = '';

      if (isset($this->request->get['page'])) {
         $url .= '&page=' . $this->request->get['page'];
      }   

         $this->document->breadcrumbs[] = array(
             'href'      => $this->url->http('custom/service' . $url),
             'text'      => $this->language->get('heading_title'),
            'separator' => $this->language->get('text_separator')
         );

      $this->data['heading_title']    = $this->language->get('heading_title');
      $this->data['heading_text']      = $this->language->get('heading_text');
      $this->id                   = 'content';
      $this->template             = $this->config->get('config_template') . 'custom/service.tpl';
      $this->layout               = 'common/layout';

      $this->render();
   }
}

catalog/view/theme/default/template/custom/service.tpl

<div class="top">
  <h1><?php echo $heading_title; ?></h1>
</div>
<div class="middle">
  <div><?php echo $heading_text; ?></div>

</div>
<div class="bottom">&nbsp;</div>

catalog/language/custom/service.php

// Heading 
$_['heading_title'] = 'Our Services';

//Content
$_['heading_text'] = 'Welcome to our services';

Also I tried the fixes mentioned in that link, but no luck.

So someone please help me to fix the problems... Any help is really appreciable ..

Upvotes: 2

Views: 3151

Answers (1)

Vidhyut Pandya
Vidhyut Pandya

Reputation: 1619

It should be $this->document->setTitle($this->language->get('heading_title'));.

And the referral link is for version 1.5.x (for older versions).You should refer files of new version and then create your new files by referring it.

Edit

The procedure is same, but you have to check for syntax changes. As in opencart 2.x and above version they have changed a lot of things and syntax.

Edit

To load common controllers like header,footer etc do this (For version 2.x)

$data['column_left'] = $this->load->controller('common/column_left');
$data['column_right'] = $this->load->controller('common/column_right');
$data['content_top'] = $this->load->controller('common/content_top');
$data['content_bottom'] = $this->load->controller('common/content_bottom');
$data['footer'] = $this->load->controller('common/footer');
$data['header'] = $this->load->controller('common/header'); 

To load the view

if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/directory/viewfile.tpl')) {
    $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/directory/viewfile.tpl', $data));
} else {
    $this->response->setOutput($this->load->view('default/template/directory/viewfile.tpl', $data));
}

Upvotes: 3

Related Questions