• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to rewrite de config > database page, dynamically

I'd like to know if CI has some helper or things like where my client can switch databases, I wanna rewrite (or edit) the config > database file, where I set url, login and pass...

Some better idea for me? Or some helper I could rewrite the PHP page?

[eluser]CI Lee[/eluser]
Sorry misread....

Lee haz no answers Sad


[eluser]Pascal Kriete[/eluser]
I don't know about rewrite, but an idea that I'll be using in an installer I have to write, is to put default config files in another folder. In those files, you change your settings to something unique.

Then, for the rewrite, you grab that file, do a str_replace on it and plop it down in the proper place.


Base_db file (application/extras/base_db.php):
//Truncated for this example

$db['default']['username'] = "__DB_USERNAME__";
$db['default']['password'] = "__DB_PASSWORD__";

// Truncated again

Now when you save the settings you do this:
//CI 1.6.2 Compat Helper (need file_put_contents)

// The new stuff we want - usually user input
$uname = 'aardvark';
$pword = 'iheartants';

// Grab the default file
$file_path = APPPATH.'extras/base_db.php';
$file = file_get_contents($file_path);

// Change the values
$file = str_replace(array('__DB_USERNAME__', '__DB_PASSWORD__'), array($uname, $pword), $file);

// Put it in the proper spot
$config_path = APPPATH.'config/database.php';
file_put_contents($config_path, $file);

hmmm, it seams cool! I'll try that Big Grin

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.