Welcome Guest, Not a member yet? Register   Sign In
How to rewrite de config > database page, dynamically
#1

[eluser]Rubiz'[/eluser]
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?
#2

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

Lee haz no answers Sad

-Lee
#3

[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.

Example:

Base_db file (application/extras/base_db.php):
Code:
//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:
Code:
//CI 1.6.2 Compat Helper (need file_put_contents)
$this->load->helper('compatibility');

// 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);
#4

[eluser]Rubiz'[/eluser]
hmmm, it seams cool! I'll try that Big Grin




Theme © iAndrew 2016 - Forum software by © MyBB