Dynamic database switching in cakephp 1.1.x

2007-06-19 Thread Mark aka drecaise

I'm trying to add a database config and use it after init. It's for an
application that numerous clients will use. Each with it's own
database. During login a master database is queried for a users
corresponding company database and the application should switch to
that database. Is this possible? (and if not, can I write a behaviour
to create that possibility?)

Mark


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Dynamic database switching in cakephp 1.1.x

2007-06-19 Thread Chris Hartjes

On 6/19/07, Mark aka drecaise [EMAIL PROTECTED] wrote:

 I'm trying to add a database config and use it after init. It's for an
 application that numerous clients will use. Each with it's own
 database. During login a master database is queried for a users
 corresponding company database and the application should switch to
 that database. Is this possible? (and if not, can I write a behaviour
 to create that possibility?)

 Mark

Behaviours don't exist in 1.1, so you're out of luck there.  Search
the google group for some info on how to create dynamic database
switching, it's in there.  I believe you can use a beforeFilter but my
mind is fuzzy today.

-- 
Chris Hartjes
Senior Developer
Cake Development Corporation

My motto for 2007:  Just build it, damnit!

@TheBallpark - http://www.littlehart.net/attheballpark
@TheKeyboard - http://www.littlehart.net/atthekeyboard

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Dynamic database switching in cakephp 1.1.x

2007-06-19 Thread rtconner

Hey Mark,

So I'm pretty sure some of the functions I used are specific to 1.2.
But you can try. I'll give you a basic overview of what I did.

I made a componant, and inside the componant in the initialize
method.. I do this:
(all the connection data is stored in a Client Model, that I load with
loadModel)

$newDb = 
ConnectionManager::create('myconn_name',
array('driver' = 'mysql'
,'host' 
= $client-data['Client']['db_host']
,'login'
= $client-data['Client']['db_login']
,'password' = 
$client-data['Client']['db_password']
,'database' = 
$client-data['Client']['db_name']
,'persistent'   = false

And then in my app_model I set
var $useDbConfig = 'myconn_name';

Again, I'm not sure at all how well this will work in 1.1


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---