Othmen215 Posted March 19, 2023 Share Posted March 19, 2023 Hi i am new to prestashop modules , i want to redirect to another page in configure page of my module i tried getAdminLink() to redirect to anothe controller but all i get is "Controller xxx is not found or invalid Any help? Link to comment Share on other sites More sharing options...
ps8modules Posted March 19, 2023 Share Posted March 19, 2023 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 More sharing options...
Othmen215 Posted March 21, 2023 Author Share Posted March 21, 2023 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? Link to comment Share on other sites More sharing options...
ps8modules Posted March 21, 2023 Share Posted March 21, 2023 Please be specific and write what other page you want to display after clicking the Save button. Link to comment Share on other sites More sharing options...
ps8modules Posted March 21, 2023 Share Posted March 21, 2023 public function postProcess() { if (Tools::isSubmit('YOUR_SUBMIT')) { /* SAVE DATA */ /* REDIRECT TO ANOTHER ADMIN LINK */ Tools::redirectAdmin($this->context->link->getAdminLink('AdminCategories')); } } 1 Link to comment Share on other sites More sharing options...
Othmen215 Posted March 21, 2023 Author Share Posted March 21, 2023 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')); } } I've already tried this and that's what i got , u can chack my ProgressBarCotroller Link to comment Share on other sites More sharing options...
ps8modules Posted March 21, 2023 Share Posted March 21, 2023 And do you have added functions in the module as I wrote? Did you add a Tab? Would you rather put the whole test module here? 1 Link to comment Share on other sites More sharing options...
Othmen215 Posted March 21, 2023 Author Share Posted March 21, 2023 (edited) 13 minutes ago, ps8moduly.cz said: And do you have added functions in the module as I wrote? Did you add a Tab? Would you rather put the whole test module here? https://codebeautify.org/alleditor/y2395325e Sorry i couldn't post any code here but here is a link Edited March 21, 2023 by Othmen215 (see edit history) 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now