Jump to content

Creating routes for a module’s controller


Recommended Posts

Posted (edited)

I am in learning stage and try to develop a module (Module for comments on product page) by following some books and prestashop documentation using Prestashop 1.6.
can someone explain how this function works. Actually I am unable to understand this complex array for routing. This is routing for "Sell all comment" on next custom page that I have created.

Can someone make me understand this array directly here or through some video or anything?
Here is the code:

public function hookModuleRoutes()
        {
            return array(
                'module-mymodcomments-comments' => array(
                    'controller' => 'comments',
                    'rule' => 'product-comments{/:module_action}/{/:id_product}/page{/:page}',
                    'keywords' => array(
                        'id_product' => array(
                            'regexp' => '[\d]+',
                            'param' => 'id_product'
                        ),
                        'page' => array(
                            'regexp' => '[\d]+',
                            'param' => 'page'
                        ),
                        'module_action' => array(
                            'regexp' => '[\w]+',
                            'param' => 'module_action'
                        ),
                    ),
                    'params' => array(
                        'fc' => 'module',
                        'module' => 'mymodcomments',
                        'controller' => 'comments'
                    )
                )
            );
        }

 

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

  • 1 month later...

Hi,

When a URL matches the pattern defined in the rule key, Prestashop will use this route configuration to process the request. It will extract the dynamic parts of the URL according to the regular expressions defined in the keywords array and pass them as parameters to the controller. The additional parameters specified in the params array will also be included in the request.

Example URL Matching

For the given rule:

Quote

product-comments{/:module_action}/{/:id_product}/page{/:page}

A URL like:

Quote

product-comments/view/123/page/2

  • module_action will be view
  • id_product will be 123
  • page will be 2

These will be extracted and passed to the comments controller within the mymodcomments module.

If you need more clarification, feel free to ask!

Thanks!

Link to comment
Share on other sites

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...