我试图弄清楚如何在后台使用控制器。
我使用的 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';
}
}
?>