Dynamically updating config data codeigniter - codeigniter

I have created my custom config file to store information about site such as if it is online or offline like-vice.
For that I have created new file in config folder and stores default values in global $config[] array with my own index.
I want to update these config data dynamically with admins control eg. he can select to put site in offline mode.
For that I have used function
$this->config->set_item('config_array_index','value_to_set');
but, I don't know why it is not working for me ?
I am not able to see any update in my config file. Also I am autoloading my config file.
Am I missing something?

Setting a config item only applies to the current session - it does not overwrite your actually codeigniter files.
If you want to permanetly take a site offline, your'll need some sort of persistant storage, such as a value in a database that is checked/updated as needed

you can create an empty config file, within your config directory , and then append your data to it using a functionality like fwrite ( you can check for some other CI function to use ).
and add it to your autoload file .

Related

How to access storage file from .env file in Laravel

I created a JSON file to use BigQuery in my Laravel project => BigQuery docs. I put the file in the storage folder to limit its access.
I only need to access it from my .env file.
GOOGLE_APPLICATION_CREDENTIALS='/storage/file.json'
Naturally, I cannot access the folder that easily and I know there are ways to access it but creating a symbolic link would make the file accessible from anywhere and I don't want that. Is there a secure way to access that file in my .env file ? Or is there a better way, another folder in which I should put the JSON file ?
I highly discourage the usage of ENV variables, instead use a Secret Manager to load at runtime, or KMS (Key Management Service)
Look at laravel-env-security for implementation.

Laravel configuration usage for different servers in pure php file

I am new in Laravel and want to know such problem
I am running an web application on several server using Laravel.
But I have encountered with an issue.
When there is modification for the project, I need to sync with git on several servers.
But it has different settings for each server (eg: DB name, DB password...)
I have set it manually because I couldn't use .env or configuration file since the file is just pure php file.
The issue I want to solve is how can I get Laravel configuration data from pure PHP file(not controller or whatever).
It will be thankful if someone teach me solution.
You asked:
how can I get Laravel configuration data from pure PHP file
The answer would be this:
You just make some file in config/ folder of laravel app (or use the existing file like config/app.php)
You make an array of your key value pairs
<?php
return [
'some_key' => 'some_value',
...
and you simply call it with this code where ever you need it:
config('config_file.key');
for example
config('app.name');
would give you Laravel by default.

Use session, cache or global variables from Laravel console

I'm processing transactions for many users, from the console/command. For each user/transaction processed, I need the user_id value accessible in a package I've created.
What would be the best way to share the user_id value to the package? Session variable? Cache helper? A global variable?
Thanks
you can use cache or config.
for config, create a global.php file in the config directory
and set your variables by Config::set('global.user_id' , $user->id) and for get that use Config::get('global.user_id')
for more information about config files read this useful link
also you can use redis database

Lumen file cache driver

I'm in Lumen, inside a Controller, and I would like to cache a computation's result in a simple and easy way, without using database or external services, so I was looking for save the cache in the filesystem. In Laravel's documentation there is cited the file driver:
By default, Laravel is configured to use the file cache driver, which
stores the serialized, cached objects in the filesystem.
And I can see it, configured as Default Cache Store, inside config/cache.php.
In Lumen's documentation i can't see anything about the file driver and I find nothing like the file cache.php inside Lumen installation.
So my question is if I can use the file cache driver in Lumen (by setting CACHE_DRIVER=file) or if it is discouraged, not supported, not implemented or something else?
In Lumen in .env.example you have by default:
CACHE_DRIVER=memcached
So all you need is to change filename from .env.example to .env and set
CACHE_DRIVER=file
If you read Caching in Lumen you'll see in example:
$value = Cache::store('file')->get('foo');
so file driver is supported by Lumen.
If you also read Lumen Configuration you can read here that you can copy configuration files you need (in case you need them) and load them manually. You can see default Luman cache config file here: https://github.com/laravel/lumen-framework/blob/5.1/config/cache.php

How do you load config settings from the database in Symfony2?

I have a number of settings that are currently in the config.yml file.
Going forward I want to be able to develop an interface where administrators will be able to update these settings, so I want to be able to manage these settings through the database.
How would I be able to load these settings from the database into Symfony2 and where and when would I load them?
Cheers
Adam
There's a cookbook article that explains roughly how to do this (albeit briefly), in reference to loading in settings externally from Drupal. The basic idea is to do something like this in your config (example is yml):
# app/config/config.yml
imports:
- { resource: parameters.php }
then in parameters.php you can do whatever you need to to get your config, and set it as follows:
$container->setParameter('my.db.parameter', $value);
(taken from the cookbook, slightly modified).
Take a look at the UnifikDatabaseConfigBundle. It creates a database structure that enable configuration of Symfony parameters straight from the database.

Resources