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.
The structure is:
- admincontrolleraddproductaddproduct.php
- adminmodeladdproductaddproduct.php
- adminlanguageaddproductaddproduct.php
- adminviewtemplateaddproductaddproduct.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.
Any help appreciated.
Subbie
I have used an ocmod to create the admin menu item.
The ocmod creates the menu item and it appears on the admin menu as expected.
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=adminviewtemplateaddproductaddproduct&user_token=BY81QNSZHHlvjChht62y28S0WnBVSCg3
Any help to solve the issue appreciated.
Below are the various pages that have been created.
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:
<?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 }}
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 }}
2
Answers
This has been solved elsewhere. The issue was a link in the OCMOD. Tghis is the correct code.
I don`t understand why your link so strange…
The correct link must like that:
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.