Phalcon\Mvc\Router - better module routing support?
I was having a heck of a time trying to figure out how to have easy module routing.
say I have two modules, main and test. I configure main as my default
/index/index (main) /main/index/index (main) /index (main)
/test (should be test but is main)
To add modules I have to add 3 routes per module to catch
/test /test/controller /test/controller/action
Can there be an easier way to automagically detect modules in the route? If I define my module in Application as
$this->registerModules(array(
'main' => array(
'className' => 'Main\Module',
'path' => \PATH . '/protected/modules/Main/Module.php'
),
'test' => array(
'className' => 'Test\Module',
'path' => \PATH . '/protected/modules/Test/Module.php'
),
));
It would be nice if the router knew that /test matched the test module somehow.
Any ideas/input?
can I check your routes?
setDefaultModule($config->phalcon->defaultModule); // Module : main $router->add('/main/:controller/:action(/?.*)', array( 'module' => 'main', 'controller' => 1, 'action' => 2, 'params' => 3, )); $router->add('/main/:controller(/?)', array( 'module' => 'main', 'controller' => 1, 'action' => 'index', )); $router->add('/main(/?)', array( 'module' => 'main', 'controller' => 'index', 'action' => 'index', )); // Module : test $router->add('/test/:controller/:action(/?.*)', array( 'module' => 'test', 'controller' => 1, 'action' => 2, 'params' => 3, )); $router->add('/test/:controller(/?)', array( 'module' => 'test', 'controller' => 1, 'action' => 'index', )); $router->add('/test(/?)', array( 'module' => 'test', 'controller' => 'index', 'action' => 'index', ));
I'm out of ideas of how can this be achieved in an easy way, if anyone have ideas they're welcome
@brandonlamb @phalcon here is a programmatic way to automate this functionality https://gist.github.com/3701633#L81
I would then just add additional modules to https://gist.github.com/3701633#L9 as needed.
Cheers!
Thanks! Plugging this in now