简体   繁体   English

Opencart 3 中的自定义页面

[英]Custom Page in Opencart 3

I am not a coder and have followed the instructions that are available to create a custom page in Opencart 3.0.3.8 under PHP 8 using localhost.我不是编码员,并且已按照可用的说明使用本地主机在 PHP 8 下的 Opencart 3.0.3.8 中创建自定义页面。

The structure is:结构是:

  • admin\controller\addproduct\addproduct.php管理员\控制器\添加产品\添加产品.php
  • admin\model\addproduct\addproduct.php管理员\模型\添加产品\添加产品.php
  • admin\language\addproduct\addproduct.php管理员\语言\添加产品\添加产品.php
  • admin\view\template\addproduct\addproduct.twig管理\查看\模板\添加产品\添加产品.twig

I have tried hard to find the problem, but with no error reports I cannot discover why the page does not load properly.我努力寻找问题所在,但没有错误报告,我无法发现页面无法正确加载的原因。 I intend to add more specific coding for my neds once the page is working properly.一旦页面正常工作,我打算为我的 neds 添加更具体的编码。 Any help appreciated.任何帮助表示赞赏。 Subbie苏比

I have used an ocmod to create the admin menu item.我使用 ocmod 来创建管理菜单项。

The ocmod creates the menu item and it appears on the admin menu as expected. ocmod 创建菜单项并按预期出现在管理菜单上。

The Users Administration boxes in the system appear and permissions are granted in both panels.出现系统中的用户管理框,并在两个面板中授予权限。

All pages load without errors.所有页面加载无误。 However when clicking the menu button the page reports:但是,当单击菜单按钮时,页面报告:

“You do not have permission to access this page, please refer to your system administrator.” “您没有访问该页面的权限,请咨询您的系统管理员。” The link is seen as – http://localhost/public_html/admin/index.php?route=admin\view\template\addproduct\addproduct&user_token=BY81QNSZHHlvjChht62y28S0WnBVSCg3该链接被视为 – http://localhost/public_html/admin/index.php?route=admin\view\template\addproduct\addproduct&user_token=BY81QNSZHHlvjChht62y28S0WnBVSCg3

Any help to solve the issue appreciated.任何解决问题的帮助表示赞赏。 Below are the various pages that have been created.以下是已创建的各种页面。 Controller: Controller:

 <?php
class ControllerAddproductAddproduct extends Controller {
    public function index() {
        
        $this->load->language('addproduct/addproduct'); // calling Add Prodduct Page language

        $this->document->setTitle($this->language->get('heading_title')); // set title from Add Prodduct Page language

        $this->load->model('addproduct/addproduct'); // calling Add Prodduct Page model
        
        $data['information_total'] = $this->model_addproduct_addproduct->getTotalInformationsOnAddproductAddproduct(); // calling model method 
        
        // breadcrumbs
        $data['breadcrumbs'] = array();

        $data['breadcrumbs'][] = array(
            'text' => $this->language->get('text_home'),
            'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
        );

        $data['breadcrumbs'][] = array(
            'text' => $this->language->get('heading_title'),
            'href' => $this->url->link('addproduct/addproduct', 'user_token=' . $this->session->data['user_token'], true)
        );
        
        // calling header, footer and column_left for our template to render properly
        $data['header'] = $this->load->controller('common/header');
        $data['column_left'] = $this->load->controller('common/column_left');
        $data['footer'] = $this->load->controller('common/footer');
        
        $this->response->setOutput($this->load->view('addproduct/addproduct', $data)); // send our $data array to view
    }
}

Language:语:

 <?php
// Heading
$_['heading_title']           = 'Add Product Page';

// Text
$_['text_custom_block']       = 'Product Page Block';
$_['text_total_informations'] = 'Total informations:';

Model: Model:

    <?php
class ModelAddproductAddproduct extends Model {
    
    public function getTotalInformationsOnAddproductAddproduct() {
        $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "information");
        return $query->row['total'];
    }

}

Twig: Twig:

 {{ header }}{{ column_left }}
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <h1>{{ heading_title }}</h1>
      <ul class="breadcrumb">
        {% for breadcrumb in breadcrumbs %}
        <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
        {% endfor %}
      </ul>
    </div>
  </div>
  <div class="container-fluid">    
    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title"><i class="fa fa-thumbs-up"></i> {{ text_custom_block }}</h3>
      </div>
      <div class="panel-body">{{ text_total_informations }} {{ information_total }}</div>
    </div>
  </div>
</div>
{{ footer }}

OCMOD:超频模式:

 {{ header }}{{ column_left }}
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <h1>{{ heading_title }}</h1>
      <ul class="breadcrumb">
        {% for breadcrumb in breadcrumbs %}
        <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
        {% endfor %}
      </ul>
    </div>
  </div>
  <div class="container-fluid">    
    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title"><i class="fa fa-thumbs-up"></i> {{ text_custom_block }}</h3>
      </div>
      <div class="panel-body">{{ text_total_informations }} {{ information_total }}</div>
    </div>
  </div>
</div>
{{ footer }}

This has been solved elsewhere.这已在其他地方解决。 The issue was a link in the OCMOD.问题是 OCMOD 中的一个链接。 Tghis is the correct code. Tghis 是正确的代码。

'href'     => $this->url->link('addproduct/addproduct', 'user_token=' . $this->session->data['user_token'], true),

I don`t understand why your link so strange... The correct link must like that:我不明白为什么你的链接这么奇怪......正确的链接必须是这样的:

https://yourdomain.loc/admin/index.php?route=addproduct/addproduct&user_token=BY81QNSZHHlvjChht62y28S0WnBVSCg3 https://yourdomain.loc/admin/index.php?route=addproduct/addproduct&user_token=BY81QNSZHHlvjChht62y28S0WnBVSCg3

My recommendation: Copy standard module in extension folder, understand how it`s work and after all of that try to write module with custom path.我的建议:在扩展文件夹中复制标准模块,了解它是如何工作的,然后尝试使用自定义路径编写模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM