Welcome Guest, Not a member yet? Register   Sign In
Running in test mode...
#1

[eluser]Leon Stafford[/eluser]
Hi,

I want to run the same site in test mode on the same domain.

Lack of foresight has a current project running live, but also very under development. Crazy, I know, but....

Is there any cool magic ways to say change the currently used database if a user is logged in?

So that my clients can log in and make changes which they can also test but not affect the main DB until they choose to sync them up?

I'm using FreakAuthLight which checks in the controllers if a user is logged in, if it gets to the controller-loading stage, can I still change the DB config?

Cheers,

Leon
#2

[eluser]Mike Ryan[/eluser]
[quote author="Leon Stafford" date="1240302999"] if it gets to the controller-loading stage, can I still change the DB config?
[/quote]

Hi Leon,

Yes, you can do this. Define your DB entries ('main' and 'test') as described in Connecting to Multiple DBs. Then in your controller you could do something like:
Code:
if ($this->session->userdata('db_name') == 'test')
{
  $DB = $this->load->database('test', TRUE);
}
else
{
  $DB = $this->load->database('main', TRUE);
}

Instead of putting this in each controller, I would suggest you extend the controller class and put this in the constructor so it gets called automatically. Remember to remove the DB class from autoload.php.
#3

[eluser]Leon Stafford[/eluser]
[quote author="Mike Ryan" date="1240344321"][quote author="Leon Stafford" date="1240302999"] if it gets to the controller-loading stage, can I still change the DB config?
[/quote]

Hi Leon,

Yes, you can do this. Define your DB entries ('main' and 'test') as described in Connecting to Multiple DBs. Then in your controller you could do something like:
Code:
if ($this->session->userdata('db_name') == 'test')
{
  $DB = $this->load->database('test', TRUE);
}
else
{
  $DB = $this->load->database('main', TRUE);
}

Instead of putting this in each controller, I would suggest you extend the controller class and put this in the constructor so it gets called automatically. Remember to remove the DB class from autoload.php.[/quote]

Thanks Mike, that should do the trick!

I'll give it a go when I get in to work tomorrow.

Cheers,

Leon




Theme © iAndrew 2016 - Forum software by © MyBB