【问题标题】:I am using Opencart Version 2.0.1.0我正在使用 Opencart 版本 2.0.1.0
【发布时间】:2017-05-03 13:24:16
【问题描述】:

我必须在 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 在 E:\xampp\htdocs\iraba\catalog\controller\information\static.php 的第 24 行没有影响

致命错误:在第 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());      
 }
}
?>

catalog/view/theme/theme536/template/information/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; ?> 

目录/语言/english/information/static.php

<?php

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

【问题讨论】:

  • 这不是您添加的链接中的代码 - OpenCart 2.0 示例。它来自那里引用的 OpenCart 1.5 示例。

标签: php opencart2.x


【解决方案1】:

您使用的某些代码在 2+ 版本上已更改。

首先你应该把以$this->data['...']开头的变量改成$data['...']。例如:

改变: $this-&gt;data['breadcrumbs'] = array();

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

此外,$this-&gt;children = array(...); 的用法已在版本 2+ 上进行了更改。 你应该像下面这样改变它。将此应用于所有子类。

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

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

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

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

希望对你有帮助。

【讨论】:

  • 还有一个错误 注意:错误:无法加载模板 E:\xampp\htdocs\iraba/catalog/view/theme/information/static.tpl!在 E:\xampp\htdocs\iraba\system\modification\system\engine\loader.php 第 45 行
  • 你能试试“.tpl”吗?如:$this->response->setOutput($this->load->view('information/static', $data));
  • 已经完成 '$this->response->setOutput($this->load->view('information/static.tpl', $data));'
  • 这里是 loader.php function 'public function view($template, $data = array()) { $file = DIR_TEMPLATE . $模板; if (file_exists($file)) { 提取($data); ob_start();需要($文件); $output = ob_get_contents(); ob_end_clean();返回$输出; } else { trigger_error('错误: 无法加载模板' . $file . '!');出口(); } }'
  • 试试怎么样:$this->response->setOutput($this->load->view($this->config->get('config_template') .'/template/information/ static.tpl', $data));
猜你喜欢
  • 2017-09-04
  • 1970-01-01
  • 2020-01-05
  • 2017-01-01
  • 2022-01-08
  • 2016-09-23
  • 2014-12-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多