Reputation: 41
This is my code. File mymodule.php:
class Mymodule extends Module {
public function __construct() {
$this->name = 'mymodule';
$this->tab = 'dashboard';
$this->version = '1.0';
$this->author = 'My Name';
$this->need_instance = 0;
parent::__construct();
$this->displayName = $this->l('My Module');
$this->description = $this->l('My module description.');
$this->confirmUninstall = $this->l('Are you sure?');
}
public function install() {
return parent::install() &&
$this->installModuleTab('MyModuleController', 'My Tab', 13);
}
public function uninstall() {
return parent::uninstall() &&
$this->uninstallModuleTab('MyModuleController'));
}
private function installModuleTab($tabClass, $tabName, $idTabParent) {
$tab = new Tab();
foreach (Language::getLanguages() as $language) {
$tab->name[$language['id_lang']] = $tabName;
}
$tab->class_name = $tabClass;
$tab->module = $this->name;
$tab->id_parent = $idTabParent;
if (!$tab->save()) {
return false;
}
return true;
}
private function uninstallInternal($class_name) {
$idTab = Tab::getIdFromClassName($class_name);
if ($idTab != 0) {
$tab = new Tab($idTab);
$tab->delete();
return true;
}
return false;
}
}
File MyModuleController.php:
class EraThemeController extends AdminController {
public function __construct() {
parent::__construct();
}
public function display() {
echo $this->l('This is my tab');
}
}
when install module, this is error:
Property Tab->name is empty
at line 887 in file classes/ObjectModel.php
when reloading the management page, tab has been created but when clicked it, this is error: Controller not found
somebody can help me?
Upvotes: 3
Views: 5734
Reputation: 2117
I am using prestashop 1.7 and in this version you declare $tabs and pretsashop on install and uninstall handle tabs by itself , I add following code in modules/module_name/module_name.php constructor:
class Plevel extends Module
{
private $c_table='plevel';
private $c_table_pivot='plevel_excluded';
public function __construct()
{
$this->tabs = array(
array(
'name' => 'Price Level', // One name for all langs
'class_name' => 'AdminPLevel',
'visible' => true,
'icon'=>'money',
'parent_class_name'=>'DEFAULT_MTR'
),
array(
'name' => 'Price Level List', // One name for all langs
'class_name' => 'AdminPLevelList',
'visible' => true,
'parent_class_name'=>'AdminPLevel',
'icon'=>'setting',
));
$this->name="plevel";
$this->tab="dashboard";
$this->version="1.0.0";
$this->author="[email protected]";
$this->need_instance=0;
$this->ps_versions_compliancy=array('min'=>'1.6','max'=>_PS_VERSION_);
$this->bootstrap=true;
$this->context=Context::getContext();
$this->displayName=$this->l("plevel");
$this->description=$this->l("change order print page");
$this->confirmUninstall=$this->l('Are you sure you want to uninstall');
parent::__construct();
}}
Upvotes: 2
Reputation: 3118
Your class should be defined like:
class AdminEraThemeController extends ModuleAdminController
Also in your module main file the name should be "AdminEraTheme", not "MyModuleController"
Upvotes: 2