Welcome Guest, Not a member yet? Register   Sign In
Permanently Update Config Items Dynamically
#1

While i was working on a CI project, there was a need to allow user set the value of the config items ( i.e not requesting values from the database). For instance most CMS offers an interface where by you can insert db name, user and password during installation process. This gave birth to a library i created Array Config Writer. check Array Config Writer on Github on git hub.

To use with CI , 


  1. Download Array Config Writer from Github and extract it under' libraries' folder of your CI project
  2. Create a new library name the class anything that suits you.
  3. include the Array_Config_Writer class and your class should extend it
  4. You can start using the class after loading.
The attached one has CI library named 'config_writer' , you can extract it under your libraries folder and test it.

Example usage 
PHP Code:
$this->load->library('config_writer', array(
'file' => APPPATH '/config/config.php' ,
'variable_name' => 'config'
));

$this->config_writer->write('compress_output' true );

// method chaining 
$this->config_writer->write('compress_output' true )->write('site_name' 'Example Site'); 

Viola the config gets updated.

For multi dimensional array like the database

PHP Code:
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'ola'
You can use
PHP Code:
$this->load->library('config_writer', array(
'file' => APPPATH '/config/database.php' ,
'variable_name' => 'db'
));

$this->config_writer->write( array('default' 'hostname') , 'my_hostname' )->write( array('default' 'username') , 'my_username' ) ; 
Reply
#2

i created a proper class with all need https://github.com/codeigniterpower/code...nfigWriter
Reply




Theme © iAndrew 2016 - Forum software by © MyBB