Setting up pretty-URL for your module

Postdate: November 19 2012
Category: Created Modules
Applies to: 2.x

Setting up pretty-URL for CTLMM modules can seem pretty intimidating. But actually it's quite easy. Here is a short HowTo.


All you need to do is edit the file Routes.php in the directory /your_module/module_specific/

First you should take look at the FAQ accessed from the modules help.
There you should find a sample that looks a bit like this:

    $routes = array(

  array(  'rule' => '"mymodule\/(?P<category>[^/]+)\/(?P<item>[^/]+)\/(?P<returnid>[0-9]+)$"',
      'builder' => array( 'mymodule'  => 'string',
                'category'  => 'param',
                'item'    => 'param',
                'returnid'  => 'param'
              ),
      'defparams' => array('action'=>'default', 'what'=>'item')
  ),

  array(  'rule' => '"mymodule\/details\/(?P<item>[^/]+)\/(?P[0-9]+)$"',
      'builder' => array( 'mymodule'   => 'string',
                'details'   => 'string',
                'item'   => 'param',
                'returnid'  => 'param'
              ),
      'defparams' => array('action'=>'default', 'what'=>'item')
  ),
  
  array(  'rule' => '"mymodule\/(?P<category>[^/]+)\/(?P<returnid>[0-9]+)$"',
      'builder' => array( 'mymodule'  => 'string',
                'category'  => 'param',
                'returnid'  => 'param'
              ),
      'defparams' => array('action'=>'default', 'what'=>'category')
  )
    
);  
 

Now that's intimidating. Isn't it? Admit it...

Lets assume that your module has 2 entities. Category and Item(to keep it pretty generic)

I marked in green where you have to put the name of your module.
I marked red where you have to insert the name of your category
And in blue the places for the real name of your items.

Remember: The routes with more parameter are coming first

Then it will look like:
..../mymodule/category/item/...

Or:
..../mymodule/details/item/...