Jump to content

{solved} Module interface


Recommended Posts

Hello.
If you want to use your own admin controller, you need to write the controller into the database when installing the module.

Your controller must be in the folder /my_module/controllers/admin/MyModuleController.php

 

Your admin module controller:

MyModuleController.php

<?php


class MyModuleController extends ModuleAdminController
{
    public function __construct()
    {
        parent::__construct();
        /* etc */
    }
}

 

Your module:

my_module.php

public function install() 
{  
        if (Shop::isFeatureActive())
        {
            Shop::setContext(Shop::CONTEXT_ALL);
        }
        
        if (!parent::install())
        {
            return false;
        }
    
        $this->installTab('install');
        
        return true;
}

public function uninstall()
{                               
        
        $this->installTab('uninstall');
        
        if (Shop::isFeatureActive())
        {
            Shop::setContext(Shop::CONTEXT_ALL);
        }
        
        if (!parent::uninstall())
        {
            return false;
        }
   
        
        return true;
}

/* add or remove controller, and add to admin left menu */
public function installTab($params) 
{ 
    if ($params == 'install') {
        $getMaxPosition = Db::getInstance()->getValue("SELECT MAX(position) FROM "._DB_PREFIX_."tab WHERE id_parent = '0' AND module IS NULL") +1;

        $tab = new Tab();
        $tab->module = $this->name;
        $languages = \Language::getLanguages(false);
        $name = array();
        foreach ($languages as $language) {
            $name[$language['id_lang']] = 'My module';
        }
        $tab->name = $name;
        $tab->class_name = 'MyModule';
        $tab->id_parent = (int)'0';
        $tab->position = (int)$getMaxPosition;
        $tab->save();
    }

    if ($params == 'uninstall') {
        $getIdByMyTab = Tab::getIdFromClassName('MyModule');
        $tab = new Tab($getIdByMyTab);
        $tab->delete();
    }
}

 

Link to comment
Share on other sites

On 3/19/2023 at 6:57 AM, ps8moduly.cz said:

Hello.
If you want to use your own admin controller, you need to write the controller into the database when installing the module.

Your controller must be in the folder /my_module/controllers/admin/MyModuleController.php

 

Your admin module controller:

MyModuleController.php

<?php


class MyModuleController extends ModuleAdminController
{
    public function __construct()
    {
        parent::__construct();
        /* etc */
    }
}

 

Your module:

my_module.php

public function install() 
{  
        if (Shop::isFeatureActive())
        {
            Shop::setContext(Shop::CONTEXT_ALL);
        }
        
        if (!parent::install())
        {
            return false;
        }
    
        $this->installTab('install');
        
        return true;
}

public function uninstall()
{                               
        
        $this->installTab('uninstall');
        
        if (Shop::isFeatureActive())
        {
            Shop::setContext(Shop::CONTEXT_ALL);
        }
        
        if (!parent::uninstall())
        {
            return false;
        }
   
        
        return true;
}

/* add or remove controller, and add to admin left menu */
public function installTab($params) 
{ 
    if ($params == 'install') {
        $getMaxPosition = Db::getInstance()->getValue("SELECT MAX(position) FROM "._DB_PREFIX_."tab WHERE id_parent = '0' AND module IS NULL") +1;

        $tab = new Tab();
        $tab->module = $this->name;
        $languages = \Language::getLanguages(false);
        $name = array();
        foreach ($languages as $language) {
            $name[$language['id_lang']] = 'My module';
        }
        $tab->name = $name;
        $tab->class_name = 'MyModule';
        $tab->id_parent = (int)'0';
        $tab->position = (int)$getMaxPosition;
        $tab->save();
    }

    if ($params == 'uninstall') {
        $getIdByMyTab = Tab::getIdFromClassName('MyModule');
        $tab = new Tab($getIdByMyTab);
        $tab->delete();
    }
}

 

i need to redirect from the save button to another page  is this code still valid?image.thumb.png.0bd09d90984087f731d5bca052515274.png

Link to comment
Share on other sites

6 minutes ago, ps8moduly.cz said:
public function postProcess()
{
    if (Tools::isSubmit('YOUR_SUBMIT')) {
        /* SAVE DATA */

        /* REDIRECT TO ANOTHER ADMIN LINK */
        Tools::redirectAdmin($this->context->link->getAdminLink('AdminCategories'));
    }
}

 

image.thumb.png.af2da1eb467cb113b13d7c0453cc19b5.png

image.thumb.png.5a309e9d3c32aaa9762b2d35cf2ec706.png

I've already tried this and that's what i got , u can chack my ProgressBarCotroller 

Link to comment
Share on other sites

  • Othmen215 changed the title to {solved} Module interface

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...