cjordan Posted November 28, 2019 Share Posted November 28, 2019 Hello can i please can anyone help me with clear example of a working custom route to a controller in a custom module? the tutorial on that is quite unclear an i am still unable to create a working route to a controller in the module i am building. Thanks. 1 Link to comment Share on other sites More sharing options...
Kogkalidis Posted November 29, 2019 Share Posted November 29, 2019 public function hookModuleRoutes($params) { $main = Configuration::get('some_config', $this->language->id); $my_routes = array( 'module-[your_module_directory]-[some_distinct_name]' => array( 'controller' => '[your_custom_controller]', 'rule' => $main . '/{link_rewrite}', 'keywords' => array( 'link_rewrite' => array('regexp' => '[_a-zA-Z0-9-\pL]*', 'param' => 'link_rewrite'), ), 'params' => array( 'fc' => 'module', 'module' => '[your_module_directory]', ), ) ); return $my_routes; } If for example your module is cjordan and your controller banana then the above code becomes public function hookModuleRoutes($params) { $main = Configuration::get('some_config', $this->language->id); $my_routes = array( 'module-cjordan-banana' => array( 'controller' => 'banana', 'rule' => $main . '/{link_rewrite}', 'keywords' => array( 'link_rewrite' => array('regexp' => '[_a-zA-Z0-9-\pL]*', 'param' => 'link_rewrite'), ), 'params' => array( 'fc' => 'module', 'module' => 'cjordan', ), ) ); return $my_routes; } and of course transplant the module in the respective hook $this->registerHook('moduleRoutes'); Just keep in mind that when calling some custom link the controller is not the "controller" but the last part of the ”module-cjordan-banana”. In this case it's the same, but in complex situations we can have for example one controller with more routes pointing there. It can be for example category_name_asc the last part in a blog module but category the controller, which means display the category X with its post ordered by name in ascending order. So in this case in the link call you put category_name_asc instead of category. Moreover, take care of the redirection when changing language. Because it does not redirect automatically. Regards, Konstantinos - a passionate PrestaShop fan. 2 1 Link to comment Share on other sites More sharing options...
cjordan Posted December 5, 2019 Author Share Posted December 5, 2019 thanks i tried following your directives and it worked perfectly 2 Link to comment Share on other sites More sharing options...
pawelszulc Posted January 29, 2020 Share Posted January 29, 2020 On 11/29/2019 at 8:31 AM, tapanda.gr said: Moreover, take care of the redirection when changing language. Because it does not redirect automatically. Hi @tapanda.gr Could you explain and give an example ? 1 Link to comment Share on other sites More sharing options...
pbeu Posted July 13, 2021 Share Posted July 13, 2021 On 11/29/2019 at 9:31 AM, tapanda.gr said: some_config I still don't understand the meaning of this phrase, is it a culprit the poor tutorial wizard? Link to comment Share on other sites More sharing options...
SmartDataSoft Posted July 18, 2021 Share Posted July 18, 2021 @pbeu The value means if you like to set any configuration value which need to change like in our case we use smart log/category as prefix of all URL. But some one like blog/category In this case blog value come from that configuration value. For more research you can ready our smart log code from git. You will find no other big prestashop module like smartblog as free. Thank you 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