Phalcon Configuration

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

    ClassDescription
    Phalcon\Config\Adapter\IniUses INI files to store settings. Internally the adapter uses the PHP function parse_ini_file.
    Phalcon\Config\Adapter\JsonUses JSON files to store settings.
    Phalcon\Config\Adapter\PhpUses PHP multidimensional arrays to store settings. This adapter offers the best performance.
    Phalcon\Config\Adapter\YamlUses YAML files to store settings.

    Comments

    Leave a Reply

    Your email address will not be published. Required fields are marked *