We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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.



98.9k

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
));