Has you see, all routes beginning with "page" or "backend/page" go in the controller "router" of module "myPageModule". With a context frontend or backend.
The action index in controller Router in module myPageModule:
OK, so I understand if I define the route backend/page(/:params) => 'myPageModule/router/index/backend in the global routes file (app/config/routes.php), it'll work
And I think :
I make a script that scans the active modules ('always_load'/modules) and construct a file app/cache/routes.php (for example) and include it in app/config/routes.php
In the end, everything is php, including your routes.php config file.
So what you could do is add a config file called 'globalroutes.php' to every module. Then in your global routes.php, get the list of loaded modules, loop over them, include these 'globalroutes.php' files, merge their contents, and return that.
You can even cache that if you don't want to do that on every page request.
"Then in your global routes.php, get the list of loaded modules, loop over them, include these 'globalroutes.php' files, merge their contents, and return that."
And It work!, i generate an admin route.php on the fly with an adminroutes.php on each module. But i don't know how doIput this filein cache.
Other solution (curiously): I saw in documentation, the method \Router::add() to manually add new routes at runtime.
Questions : - where can i use it in my code to execute it before Request construct ? In a router() method,or _init() function of my base controller? - what is thepriority of thisnew route added relative to the module route? It will be prepended to the routes array?
Router::add() by default appends. You can have it prepend by passing TRUE as third argument. Routes in your routes.php config are processed top to bottom in the order in which they are defined.
Router::add() isn't that useful for main requests, as the only place you could use it is in your app bootstrap (not very logical) or your router config (but there you define routes anyway). It is mainly used to add routes dynamically for HMVC calls, so secondary requests.