It is a component which is used to convert configuration files into PHP. Its directory location is Phalcon\Config.
Implementation
<?php
use Phalcon\Config;
$config = new Config(
[
'test' => [
'parent' => [
'property' => 1,
'property2' => 'yeah',
],
],
]
);
echo $config->get('test')->get('parent')->get('property');
// displays 1
echo $config->test->parent->property;
// displays 1
echo $config->path('test.parent.property');
// displays 1
?>
Example: To convert native array into Phalcon\Config Objects.
<?php
use Phalcon\Config;
$settings = [
'database' => [
'adapter' => 'Mysql',
'host' => 'localhost',
'username' => 'sid',
'password' => 'javatpoint',
'dbname' => 'test_db'
],
'app' => [
'controllersDir' => '../app/controllers/',
'modelsDir' => '../app/models/',
'viewsDir' => '../app/views/'
],
'mysetting' => 'the-value'
];
$config = new Config($settings);
echo $config->app->controllersDir, "\n";
echo $config->database->username, "\n";
echo $config->mysetting, "\n";
?>
File Adapters
Class | Description |
---|---|
Phalcon\Config\Adapter\Ini | Uses INI files to store settings. Internally the adapter uses the PHP function parse_ini_file. |
Phalcon\Config\Adapter\Json | Uses JSON files to store settings. |
Phalcon\Config\Adapter\Php | Uses PHP multidimensional arrays to store settings. This adapter offers the best performance. |
Phalcon\Config\Adapter\Yaml | Uses YAML files to store settings. |
Leave a Reply