Yii:: Setting static properties of modules in config

July 14, 2012, 3:00 PM

The light trick not to break your OOP model structure

You may face a situation when you need to access to a configurable module's property from everywhere and you don't have an instance of this module's class.

array( 'dbConnection' => 'db', //. . . ) ); ?> _db = new AADb($this->_data); AADb::$dbConnection =& $this->dbConnection; } } class AAFieldForeign extends AAField implements AAIField { //. . . private function selectDefault() { $q = Yii::app()->{AADb::$dbConnection}->createCommand(); //. . . } } ?>

So as you can see you get an access to the property $dbConnection which can be configured by user. And it's accessible as static through the special class (of course not only for this). And you can change the value of the property if you need (but look after succession of operations).