PHP code example of ibnusyuhada / slim-lite-configuration

1. Go to this page and download the library: Download ibnusyuhada/slim-lite-configuration library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ibnusyuhada / slim-lite-configuration example snippets


// configuration only available in this route
$app->get("/", function($req,$res,$args){
	var_dump($this->settings);
})->add($container->get("config"));

$app = new \Slim\App;
$container = $app->getContainer();
$container["config"] = function ($container){
	return new IS\Slim\LiteConfiguration\Configuration(__DIR__ . "/../config/config.yaml",$container);
};

// register for all routes
$app->add($container->get("config"));

$app->get("/", function($req,$res,$args){
	var_dump($this->settings);
});

$app->get("/blog", function($req,$res,$args){
	var_dump($this->settings);
});

$app->run();

$app->get("/blog", function($req,$res,$args){
	$conf = $this->config;
	
	$array = [
			"coba" => "hasil",
			"first_section" => [
					"three" => 1,
					"two" => 2
			],
			"phpversion" => [
					"one","two"
			],
			"second_section" => [
					"servers" => ["host1","host2","host3"]
			]
	];
	
	$conf->writeConfig($array,dirname(dirname(__FILE__)) . "/config/config.yaml");
	return success;
});

$settings = $this->settings;
var_dump($settings);

$conf = $this->config;
var_dump($conf->all());

$settings = $this->settings;
var_dump($settings["db"]["host"]);

$conf = $this->config;
var_dump($conf->get("db.host"));

$conf = $this->config;
echo $conf->get("db.host"); // output is localhost
$conf->set("db.host","ibnu");
echo $conf->get("db.host"); // output is ibnu

$container["config"] = function ($container){
	return new IS\Slim\LiteConfiguration\Configuration(__DIR__ . "/../config",$container);
};