Partial uri routing

Is it possible to write a route that would be executed even on partial uri. Suppose I have uri like :/module/controller/action/param1/val1.... Then next route works fine

<?php
$router -> add ('/:module/:controller/:action/:params', array(
    'module' => 1,
    'controller' => 2,
    'action' => 3,
    'params' => 4
));

But when only part of the uri supplied, like /module/controller/ this route doesn't work. Is it possible to make a route that would use defaults when only part of uri matched. Like when only module name is supplied, default controller would be used and so on.



84.5k

You need at least two routes to achieve that:

$router -> add ('/:module/:controller', array(
    'module' => 1,
    'controller' => 2    
));

$router -> add ('/:module/:controller/:action/:params', array(
    'module' => 1,
    'controller' => 2,
    'action' => 3,
    'params' => 4
));