Hi Bruce,

I want to do exactly the same than you.
I have 4 db, 1 how contain the other DB name and the 3 other db have
the same shema.
I check with a prefix in the url if it corespond to a existing client
name in the first DB and then I want to change the default database.
I tried to do that :

function checkPrefix() {
                strtok(env('REQUEST_URI'), '/');
                $prefix = strtok('/');
                $companies = $this->Company->findByName($prefix);
                if (empty($companies))
                {
                        $this->Session->setFlash('bad company prefix in the 
URL');
                        $this->redirect('/users/newcompany');
                        exit();
                }
                $company_name = $prefix;
                $db_used = $companies['Company']['db_name'];
                $db =& ConnectionManager::getDataSource('default');
                $db->reconnect(array('database' => $db_used));
                $this->Session->write('companyName', $prefix);
                $this->Session->write('dbUsed', $db_used);
        }

But I have a problem with the $db->reconnect function, it does use the
pass and user name stored in the database.php file.

I tried like that instead of the reconnect function:
       $db->disconnect();
       $db->config['database'] = $db_used;
       $db->connect();

But the database does not change :( maybe I have to do a reconnect
each time a load a new page...)

If you have resolved your problem I am very interested by the
solution.

Regards

Sebastien

On Aug 18, 9:22 am, Bruce <[EMAIL PROTECTED]> wrote:
> OK, I have tried things out on a very simple app, and have the
> database switching working from a constructor in app_model. But I am
> back to my initial problem of needing a way to direct the logic from
> the controller somehow.
>
> What I am intending to do is to access a family of controllers through
> a central controller, setting the initial config values based on the
> initial path. I have that part working fine between controllers, but
> the behavior I don't seem to be able to read Session values or I
> assume Configure values. I assume that this is because controllers are
> processed after the AppModel code. Is there any way other than
> Sessions and Configure to carry values to subsequent pages?
>
> So in app_model, I have a constructor as follows:
>
>  function __construct($id = false, $table = null, $ds = null) {
>         parent::__construct();
>         $this->useDbConfig = 'dbname';
>  }
>
> I want to be able to use some sort of variable value, based on logic
> in an upstream page, in place of 'dbname'. If I was doing this in the
> controller, I would use a session variable or a configuration value.
> Maybe I should do the DbConfig thing in the controller, but that would
> seem to me to be a kludge of the MVC approach.
>
> On Aug 14, 10:53 pm, "Dardo Sordi Bogado" <[EMAIL PROTECTED]>
> wrote:
>
> > When overriding a model constructor, ie __construct() you have to
> > respect the parent constructor signature (take the same parameter
> > count) and call parent::__construct() with the given/custom parameters
> > that the parent constructor is expecting.
>
> > Also, showing the errors you get would help us help you.
>
> > For further reference, read the Model::__construct() function 
> > here:http://api.cakephp.org/1.2/libs_2model_2model_8php-source.html#l00314
>
> > HTH,
> > - Dardo Sordi.
>
> > On Thu, Aug 14, 2008 at 8:31 AM, Bruce <[EMAIL PROTECTED]> wrote:
>
> > > I am working on a somewhat complex application that involves multiple
> > > models. If everything works out, there will be multiple instances of
> > > the application for different clients, and my current intention is to
> > > separate each instance into a separate database.
>
> > > I am very much a self taught programmer, with no PHP training, so I
> > > occasionally find it hard to follow some of the documentation where
> > > background PHP knowledge is assumed.
>
> > > I got things working fairly well at first, using some code in the
> > > database configuration to set the database definition based on the
> > > url. However that is only satisfactory for a single model. I am now
> > > looking at alternative ways to set the database definition, possibly
> > > from the model. I will access the application throgh a single entry
> > > point, which will set Session variables based on the url. Other
> > > controllers will then be called from that model and use the session
> > > data and config variables to set up the varoius instances.
>
> > > I found some references to using __construct(), but when I add an __
> > > construct function in app_model.php I get errors.
>
> > > Before I head further down this track, does anyone know if I can see
> > > Session values from within a construct function in app_model? This is
> > > fundamental to my planned approach. I also need to be sure that I can
> > > sitch the default database from this construct function.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to