Yii Params Database

hello i have following problem :

I want make params value in my config/main.php file following :




'params'=>array(

'adminEmail'=>'webmaster@example.com',

)



but i want a value be from database like this:




'params'=>array(

'adminEmail'=>SiteConfiguration::getKey('ADMIN_EMAIL'),

)



Anyone can resolve my problem? or in yii can i do that?

Not really in the way you’re attempting. You’re trying to access the model from the database file, but the model relies on the database settings within that file to connect to the database.

I’m sure there are ways to do what you’re attempting (perhaps with a callback function or attaching to one of the Yii application life-cycle events), but it might make more sense to access these dynamic settings from a separate component when you require them. You’re then not obscuring the fact that the data comes from a different source.

I’m using following soultion modified from http://www.yiiframework.com/wiki/304/setting-application-parameters-dynamically-in-the-back-end/ but instead of file i using this function:




		function getKey($key)

		{

			$db = mysql_connect('xxx', 'xxx', 'xxx');

			mysql_select_db('xxx');

			$sql = "SELECT `value` FROM site_configuration WHERE `key`='$key'" ;

			$result = mysql_query($sql);

			$row = mysql_fetch_row($result);

			mysql_close($db);

			return $row[0];		


		}



But i don’t know that this solution is the best way ;/

Maybe you can get some ideas from this wiki article?