The way I’m currently doing something similar (but not from a DB!), I create a configuration file (ie. config.php) and include it before the main.php file loads.
In the config.php I have constants holding my desired variables (ie: MYTHEME = theme, MYSQLSTRING = mysql connection string, MYAPPNAME = app name … and so on)
and in the main.php I call these constants - this way, I don’t have to store sensitive information in my main.php file (I mostly use public source control solutions)
After that, I’ve created a MyController.php inside components directory that extends CController. Other controllers, inside “controller” dir will extends MyController. In MyController.php I have init() done in this way:
public function init(){
Yii::app()->config->load(); //it loads all data stored in DB, look dbparam for doc
Yii::app()->theme = Yii::app()->config->theme; // overwrite default "theme" value, stored in config/main.php
Yii::app()->name = Yii::app()->config->name; //overwrite default "name" application value, stored in config/main.php
// .... and so on...
}
Because init() method will loaded first, from "root" controller, Yii::app()->{whatever} will be available for whole application.
It looks ugly, I know, but at moment it’s only way I’ve found to solve my problem. Other suggestions/solutions are welcome, of course