📜  Phalcon配置

📅  最后修改于: 2021-01-07 09:17:02             🧑  作者: Mango

Phalcon配置

它是用于将配置文件转换为PHP的组件。它的目录位置是Phalcon \ Config。

实作

 [
            '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

?>

示例:将本机数组转换为Phalcon \ Config对象。

 [
        '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";

?>

文件适配器

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.