Jump to content

Custom tab in Back-office main menu


Recommended Posts

How to create custom tab in Back-office main menu to my new custom module?

Name module: mymodule

private function installTab()
    {
        $parent_tab = new Tab();
        $parent_tab->name = array();
        foreach (Language::getLanguages(true) as $lang)
        $parent_tab->name[$lang['id_lang']] = 'Theme Settings';
        $parent_tab->class_name = 'AdminMyModule';
        $parent_tab->id_parent = 0;
        $parent_tab->module = $this->name;
        $parent_tab->add();
        $tab = new Tab();  
        $tab->name = array();
        foreach (Language::getLanguages(true) as $lang)
        $tab->name[$lang['id_lang']] = 'Theme Settings';
        $tab->class_name = 'AdminMyModule';
        $tab->id_parent = $parent_tab->id;
        $tab->module = $this->name;
        $tab->add();
        return true;
    }

I need 1 tab, only parent, but it dont work without $tab = new Tab(); (only Tab and Parent tab).

Controller

<?php class AdminMyModuleController extends ModuleAdminController {

    public function __construct()
    {
        parent::__construct();
        Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules').'&configure=mymodule');
    }

}

1) Am I right?

2) What right method?

3) How can I make uninstall parentTab and Tab?

4) Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules').'&configure=mymodule') ---->>>> I want to have active Tab of module.

Edited by workstyling (see edit history)
Link to comment
Share on other sites

  • 2 years later...

This is my code to create Menu & Sub Menu on back Office

private function _createTab()
    {
        $res = true;
        $tabparent = "AdminGformbuilderpro";
        $id_parent = Tab::getIdFromClassName($tabparent);
        if(!$id_parent){
            $tab = new Tab();
            $tab->active = 1;
            $tab->class_name = "AdminGformbuilderpro";
            $tab->name = array();
            foreach (Language::getLanguages() as $lang){
                $tab->name[$lang["id_lang"]] = "Form Builder Pro";
            }
            $tab->id_parent = 0;
            $tab->module = $this->name;
            $res &= $tab->add();
            $id_parent = $tab->id;
        }
        $subtabs = array(
            array(
                'class'=>'AdminGformconfig',
                'name'=>'Genaral Settings'
            ),
            array(
                'class'=>'AdminGformmanager',
                'name'=>'Form'
            ),
            array(
                'class'=>'AdminGformrequest',
                'name'=>'Received Data'
            ),
            array(
                'class'=>'AdminGformrequestexport',
                'name'=>'CSV Export'
            ),
        );
        foreach($subtabs as $subtab){
            $idtab = Tab::getIdFromClassName($subtab['class']);
            if(!$idtab){
                $tab = new Tab();
                $tab->active = 1;
                $tab->class_name = $subtab['class'];
                $tab->name = array();
                foreach (Language::getLanguages() as $lang){
                    $tab->name[$lang["id_lang"]] = $subtab['name'];
                }
                $tab->id_parent = $id_parent;
                $tab->module = $this->name;
                $res &= $tab->add();
            }
        }
        return $res;
    }
Link to comment
Share on other sites

good solution.

i made controller...

class AdminTSConfigController extends ModuleAdminController {

    public function __construct()
    {
        parent::__construct();
        Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules').'&configure=templatesettings');
    }
}

Link to comment
Share on other sites

×
×
  • Create New...