I have a problem in preparing a simple module that displays the word TEST both in the admin panel and on the user’s side after accessing his account
Module structure:
[1]: https://i.sstatic.net/XZeHl4cg.png
controllers/admin/AdminTestController.php
<?php
class AdminTestController extends ModuleAdminController
{
public function __construct()
{
parent::__construct();
}
public function initContent()
{
parent::initContent();
$this->setTemplate('test.tpl');
}
}
controllers/front/TestController.php
<?php
use PrestaShopPrestaShopCoreModuleWidgetInterface;
class TestModuleTestModuleTestController extends ModuleFrontController
{
public function initContent()
{
parent::initContent();
$this->context->smarty->assign([
'message' => 'TEST'
]);
$this->setTemplate('module:testmodule/views/templates/front/test.tpl');
}
}
views/template/admin/test.tpl
<h1>TEST</h1>
views/template/front/test.tpl
<!-- modules/testmodule/views/templates/front/test.tpl -->
<div>
<a href="{$link->getModuleLink('testmodule', 'test')}">SEE DATA</a>
</div>
/testmodule.php
<?php
if (!defined('_PS_VERSION_')) {
exit;
}
class TestModule extends Module
{
public function __construct()
{
$this->name = 'testmodule';
$this->tab = 'front_office_features';
$this->version = '1.0.0';
$this->author = 'Your Name';
$this->need_instance = 0;
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Test Module');
$this->description = $this->l('A simple module to display TEST on both admin and user pages.');
$this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_);
}
public function install()
{
return parent::install() &&
$this->registerHook('displayCustomerAccount') &&
$this->registerHook('displayAdminProductsMainStepLeftColumnMiddle');
}
public function hookDisplayCustomerAccount($params)
{
$link = $this->context->link->getModuleLink('testmodule', 'test');
return '<a href="' . $link . '">SEE DATA</a>';
}
}
The problem is that the link from /front/test.tpl redirects to localhost:8080/en/module/testmodule/test.
I’ll just add that I’ve been using the Prestashop documentation for the most part and yet these errors appear
Another thing is that on the admin side there is no redirect to this view, on other attempts there was an error status 500 and a store operation error, and the link itself led to the same as above only that for admin
The module itself installed without problems, it appears in the /modules tab
Have any of you encountered something like this?
Environment: Docker - windows 10
Prestashop: 8.1