A continuation from previous question: Custom lithium routing scenario
Note: This is specific to the Lithium Framework
The Problem
I've inherited a URL scheme that doesn't really have any convention to differentiate between pages, items and categories. So, I've got a very generic router that passes to a catch-all controller.
This catch-all controller (PagesController) uses the url as key to retrieve Page Type from a database. The PagesController then runs methods and chooses templates based on a Page Type. I store this information in Memcached indefinitely, so lookups are quite fast.
However, as more page types come into play, I can see this controller becoming too bloated and inflexible. Ideally, I would like to break the different page types out into their own controllers.
The Solution?
Would it be possible to have a routing scenario that checks the database to determine the correct controller?
My first thought is to subclass lithium\net\http\Router
and use custom logic in Router::connect()
and Router::_parseController()
.
It would be nice if could query the database in bootstrap\routes.php and create a new lithium\net\http\Route
object based on the results. Then, simply pass this to Router::connect()
. This seems like an awful hack.
Either way, Router::connect()
in it's design isn't meant to be that dynamic.