DS.'myExtension.ini';
$registry =& JFactory::getConfig();
$ini = $registry->toString('INI', 'myExtension');
// save INI file
JFile::write($file, $ini);
Exporting in XML format is identical except that we substitute all occurrences of
INI with XML. Exporting to PHP is slightly different. The site configuration file,
configuration.php, is a prime example of using a PHP file to store data.
The PHP format saves values into a class. In the case of the site configuration,
the class is called JConfig. We must provide, as a string parameter, the name of
the class as which we wish to save the settings when we use the JRegistry
toString() method.
Extension Design
[ 176 ]
This example demonstrates how we would export the settings to a PHP class named
SomeClass:
// import JFile
jimport('joomla.filesystem.file');
// prepare for save
$file = JPATH_COMPONENT.DS.'myExtension.php';
$registry =& JFactory::getConfig();
$php = $registry->toString('PHP', 'myExtension',
array('class'=>'SomeClass'));
// save PHP file
JFile::write($file, $php);
If you choose to use this mechanism to store settings, it is important to consider the
best file format for your settings.
Pages:
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247