我正在使用Opencart版本2.0.1.0

时间:2017-05-03 13:24:17

标签: php opencart2.x

我必须在Opencart中创建新页面。但我不知道如何开始。所以我按照给定的链接

https://forum.opencart.com/viewtopic.php?f=23&t=136937

但是我收到了错误

注意:间接修改重载属性ControllerInformationStatic :: $ data对第10行的E:\ xampp \ htdocs \ iraba \ catalog \ controller \ information \ static.php没有影响

注意:间接修改重载属性ControllerInformationStatic :: $ data对第12行的E:\ xampp \ htdocs \ iraba \ catalog \ controller \ information \ static.php没有影响

注意:间接修改重载属性ControllerInformationStatic :: $ data在第18行的E:\ xampp \ htdocs \ iraba \ catalog \ controller \ information \ static.php中无效

注意:间接修改重载属性ControllerInformationStatic :: $ data在第24行的E:\ xampp \ htdocs \ iraba \ catalog \ controller \ information \ static.php中无效

致命错误:在第41行的E:\ xampp \ htdocs \ iraba \ catalog \ controller \ information \ static.php中调用未定义的方法ControllerInformationStatic :: render()

如链接中所述,我创建了三个文件:

目录/控制器/信息/ static.php

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

 public function index() {
  $this->language->load('information/static'); 

   $this->document->setTitle($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
     );

     $this->data['breadcrumbs'][] = array(
       'text'      => $this->language->get('heading_title'),
     'href'      => $this->url->link('information/static'),
       'separator' => $this->language->get('text_separator')
     );   

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

  if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/information/static.tpl')) { //if file exists in your current template folder
     $this->template = $this->config->get('config_template') . '/template/information/static.tpl'; //get it
  } else {
     $this->template = 'theme536/template/information/static.tpl'; //or get the file from the default folder
  }

  $this->children = array( //Required. The children files for the page.
     'common/column_left',
     'common/column_right',
     'common/content_top',
     'common/content_bottom',
     'common/footer',
     'common/header'
  );

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

目录/视图/主题/ theme536 /模板/信息/ static.tpl

<?php echo $header; ?>
<div class="container">
<ul class="breadcrumb">
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<li><a href="<?php echo $breadcrumb['href']; ?>"><?php echo 
$breadcrumb['text']; ?></a></li>
<?php } ?>
</ul>
<div class="row"><?php echo $column_left; ?>
<?php if ($column_left && $column_right) { ?>
<?php $class = 'col-sm-6'; ?>
<?php } elseif ($column_left || $column_right) { ?>
<?php $class = 'col-sm-9'; ?>
<?php } else { ?>
<?php $class = 'col-sm-12'; ?>
<?php } ?>
<div id="content" class="<?php echo $class; ?>"><?php echo $content_top; ?>
  <h1><?php echo $heading_title; ?></h1>
  YOUR OWN CONTENTS
   <?php echo $content_bottom; ?></div>
 <?php echo $column_right; ?></div>
</div>
<?php echo $footer; ?> 

目录/语言/英语/信息/ static.php

<?php

$_['heading_title']  = 'Static Page';
?>

1 个答案:

答案 0 :(得分:0)

您使用的部分代码已在版本2 +&#39上更改。

首先,您应该将以$ this-&gt;数据[&#39; ...&#39;]开头的变量更改为$ data [&#39; ...&#39;]。例如:

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

作为:$data['breadcrumbs'] = array();

{2}版本的$this->children = array(...);用法也已更改。 你应该改变这个,如下所示。适用于所有儿童课程。

$data['column_left'] = $this->load->controller('common/column_left');

最后,您应该更改响应输出。

更改:$this->response->setOutput($this->render());

作为:$this->response->setOutput($this->load->view('information/static.tpl', $data));

我希望,这有帮助。