This simple class may help you to use .INI files on your projects.
Developed with Yii 1.1.6
Unzip the contents on the package onto your protected/extensions folder. The package has a sample .INI file for testing purposes named settings.ini. For the sake of the example, I assume you have that file.
// Import the library Yii::import('ext.helpers.EIniHelper'); // path reference to the .INI file $ini = Yii::getPathOfAlias('ext.helpers').DIRECTORY_SEPARATOR.'settings.ini'; // Load the whole section (please review the example .INI file) // The static Load method has Singleton functionality // so only one instance per file is always maintained $iniF = EIniHelper::Load($ini)->Get('Database'); // echo one of the values echo $iniF['database'].'<br/>'; // We can also load a single parameter $iniF = EIniHelper::Load($ini)->Get('Database','dbtype'); echo $iniF.'<br/>'; // Load $iniF = EIniHelper::Load($ini)->Get('Parameters','webmaster'); echo $iniF.'<br/>';
Be the first person to leave a comment
Please login to leave your comment.