簡體   English   中英

Opencart 3 中的自定義頁面

[英]Custom Page in Opencart 3

我不是編碼員,並且已按照可用的說明使用本地主機在 PHP 8 下的 Opencart 3.0.3.8 中創建自定義頁面。

結構是:

  • 管理員\控制器\添加產品\添加產品.php
  • 管理員\模型\添加產品\添加產品.php
  • 管理員\語言\添加產品\添加產品.php
  • 管理\查看\模板\添加產品\添加產品.twig

我努力尋找問題所在,但沒有錯誤報告,我無法發現頁面無法正確加載的原因。 一旦頁面正常工作,我打算為我的 neds 添加更具體的編碼。 任何幫助表示贊賞。 蘇比

我使用 ocmod 來創建管理菜單項。

ocmod 創建菜單項並按預期出現在管理菜單上。

出現系統中的用戶管理框,並在兩個面板中授予權限。

所有頁面加載無誤。 但是,當單擊菜單按鈕時,頁面報告:

“您沒有訪問該頁面的權限,請咨詢您的系統管理員。” 該鏈接被視為 – http://localhost/public_html/admin/index.php?route=admin\view\template\addproduct\addproduct&user_token=BY81QNSZHHlvjChht62y28S0WnBVSCg3

任何解決問題的幫助表示贊賞。 以下是已創建的各種頁面。 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
    }
}

語:

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

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

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:

 {{ 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 }}

超頻模式:

 {{ 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 中的一個鏈接。 Tghis 是正確的代碼。

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

我不明白為什么你的鏈接這么奇怪......正確的鏈接必須是這樣的:

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

我的建議:在擴展文件夾中復制標准模塊,了解它是如何工作的,然后嘗試使用自定義路徑編寫模塊。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM