cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

Phalcon\Mvc\Router - better module routing support?

Open brandonlamb opened this issue 14 years ago • 5 comments

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?

brandonlamb avatar Sep 19 '12 01:09 brandonlamb

can I check your routes?

ghost avatar Sep 19 '12 03:09 ghost

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

brandonlamb avatar Sep 22 '12 19:09 brandonlamb

I'm out of ideas of how can this be achieved in an easy way, if anyone have ideas they're welcome

ghost avatar Sep 25 '12 17:09 ghost

@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!

nesbert avatar Sep 26 '12 17:09 nesbert

Thanks! Plugging this in now

brandonlamb avatar Oct 03 '12 05:10 brandonlamb