如何解决Prestashop 模块管理控制器页面未找到
我想弄清楚如何在后台使用控制器。
我使用的 prestashop 版本是 1.7.7.4。
我想在后台创建一个页面。
我在“/modules/MyModule/controllers/admin/MyModuleController.PHP”中创建了一个控制器“MyModuleController”,但在后台出现消息“控制器 MyModuleController 缺失或无效"。
我究竟做错了什么?
下面是我写的代码:
/modules/MyModule/MyModule.PHP
<?PHP
class MyModule extends Module
{
public function __construct()
{
$this->name = 'MyModule';
$this->tab = 'administration';
$this->version = '1.0.0';
$this->author = 'Firstname Lastname';
$this->need_instance = 0;
$this->ps_versions_compliancy = [
'min' => '1.6','max' => _PS_VERSION_
];
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('My module');
$this->description = $this->l('Description of my module.');
$this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
}
public function install()
{
// Install Tabs
$tab = new Tab();
$tab->active = 1;
$tab->class_name = "MyModuleController";
$tab->module = 'mymodule';
$tab->name = array();
$tab->id_parent = (int)Tab::getIdFromClassName('SELL');
$tab->position = 3;
foreach ($lang as $l) {
$tab->name[$l['id_lang']] = $this->l('Mon module');
}
$tab->add();
parent::install();
}
public function uninstall()
{
// Uninstall Tabs
$tab = new Tab((int)Tab::getIdFromClassName('Mymodule'));
$tab->delete();
// // Uninstall Module
parent::uninstall();
}
}
/modules/MyModule/controllers/admin/MyModuleController.PHP
<?PHP
class MyModuleController extends ModuleAdminController
{
public function __construct()
{
parent::__construct();
$this->bootstrap = true;
$this->id_lang = $this->context->language->id;
$this->default_form_language = $this->context->language->id;
}
public function initContent()
{
parent::initContent();
return echo 'hello';
}
}
?>
解决方法
遵循 Prestashop 默认模块:
模块 ps_linklist:
$this->name = 'ps_linklist';
$this->author = 'PrestaShop';
$this->version = '3.2.0';
$this->need_instance = 0;
$this->tab = 'front_office_features';
$this->tabs = [
[
'class_name' => 'AdminLinkWidget','visible' => true,'name' => 'Link Widget','parent_class_name' => 'AdminParentThemes',],];
您的管理员控制器的名称必须以“Admin”开头
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。