Is there any way to load the routes from a DB? I mean currently the way it works Yii first initializes the routes and then only loads the DB class. So i have no way of accessing the DB while the routes are loaded. Even when i preload the DB class i still don’t have the access to the DB to load the routes from the DB rather then files.
You can make a small class/function to load a list of routes, using standard php/mysql connection. If necessary you can use the same config file to get the database parameters…
But than you would have a double DB connection active on every request…
What I would do is: on changes to your routes table, just write it to a file too (config/routes.php), and include that in your config file.
I have something like that in my custom i18n component (but I include different rule-files instead of doing db-queries).
Just create a special component and make sure it gets preloaded. In the init-function of the component you read the rules from the db and setup the UrlManager (re-init):