Рекурсивный акроним словосочетания «PHP: Hypertext Preprocessor»
Добро пожаловать на форум PHP программистов!
За последние 24 часа нас посетили 17414 программистов и 1874 робота. Сейчас ищут 1742 программиста ...
Editing a configuration
Вернуться к: Introduction
There are many ways to create content in your Config object. You can simply pass it an array like it is shown in the example below:
Create configuration with array
<?php
// configuration array
$conf = array(
'DB' => array(
'type' => 'mysql',
'host' => 'localhost',
'user' => 'root',
'pass' => 'root'
)
);
// Config object
$config = new Config();
$root =& $config->parseConfig($conf,
'phparray',
array('name' => 'conf'));
echo $root->toString('phparray', array('name' => 'conf'));
?>
You can also ask Config to look for a file on your filesystem and try to parse it. You would then do it like this. This example assumes you have a valid XML file:
Create configuration with a file
<?php
// Config object
$config = new Config();
$root =& $config->parseConfig('/path/to/file.xml', 'xml');
echo $root->toString('phparray', array('name' => 'conf'));
?>
At the moment, Config can parse XML, PHP arrays, ini files, Apache conf and other generic type of configurations with comments and key-value pairs.
Of course, it is also possible to create the configuration from scratch as shown in the previous section example.
Вернуться к: Introduction