Thanks for your help

it is now working perfectly. I've added a small helper function into
the model to make things a lot easier:

function setSource($tableName) {
                $this->setDataSource($this->useDbConfig);
                $db =& ConnectionManager::getDataSource($this->useDbConfig);
                $db->cacheSources = $this->cacheSources;

                if ($db->isInterfaceSupported('listSources')) {
                        $sources = $db->listSources($this);
                        if (is_array($sources) && 
!in_array(low($this->tablePrefix .
$tableName), array_map('low', $sources))) {
                                return $this->cakeError('missingTable', 
array(array(
                                        'className' => $this->name,
                                        'table' => $this->tablePrefix . 
$tableName
                                )));
                        } else {
                                $this->table = $tableName;
                                $this->tableToModel[$this->table] = $this->name;
                                $this->_tableInfo = null;
                                $this->loadInfo();
                        }
                } else {
                        $this->table = $tableName;
                        $this->tableToModel[$this->table] = $this->name;
                        $this->loadInfo();
                }
        }


Once I set the new parameters into my "alt" dbconfig, I simply call
$this->Dummy->setSource("alt"); and eveything works exactly as it
should! The only thing I had to do was to let the dummy model point to
a working database config (and table) to begin with.

Hopefully this may help others, I cannot be the only person to want
and need this level of dynamic control.

Many thanks

Mike
On Sep 6, 12:29 pm, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> I would take a look at Model::loadInfo() if I were you, also
> Model::primaryKey
>
> Hope they help!
>
> Simon
>
> On Sep 6, 11:44 am, "Mike Green" <[EMAIL PROTECTED]> wrote:
>
> > Thanks for that, I've got slightly further along which i'm very very
> > happy about. I still need to find a way of "discovering" what any
> > particular table's primarykey is, otherwise my paginator will keep
> > trying to find a field called "ID".
>
> > Many thanks
>
> > MIke
>
> > On 06/09/07, [EMAIL PROTECTED]
>
> > <[EMAIL PROTECTED]> wrote:
>
> > > Your best bet here is to create new config members in the
> > > DATABASE_CONFIG class, you can then use DataSource:reconnect to swap
> > > your alt config for the others you've just created. Your models would
> > > then useDbConfig alt, which would actually no longer be alt, but
> > > whichever config you reconnected to.
>
> > > eg.
> > > $db = ConnectionManager :: getDataSource('alt');
> > > $db->reconnect($dbConfig->{$to});
>
> > > Of course you don't even need to create the other dbs in
> > > DATABASE_CONFIG. You can just pass the array straight into reconnect
> > > above, I just find it more elegant in my use case to prepare config
> > > for all the possible dbs I might want in the config code in advance.
>
> > > Simon
>
> > > On Sep 6, 11:12 am, "Mike Green" <[EMAIL PROTECTED]> wrote:
> > > > Dear all
>
> > > > Has anybody here successfully created a database config and model
> > > > dynamically using the latest cake 1.2? I want to create something not
> > > > a million miles away from phpmyadmin, and as you can imagine, for an
> > > > app like that, you cant pre-set the database or models before hand as
> > > > you know nothing about the data source.
>
> > > > Ideally, I'd like to read a database config file (from anywhere, an
> > > > ini file, fields from a database, input from a user) and then be able
> > > > to create the dbconfig on the fly - which I can do using something
> > > > like:
>
> > > > $_this =& ConnectionManager::getInstance();
> > > > $_this->config->alt['password']=$info['db_pass'];
> > > > $_this->config->alt['login']=$info['db_user'];
> > > > $_this->config->alt['database']=$info['db_name'];
> > > > $_this->config->alt['host']=$info['db_host'];
>
> > > > where alt is just a dummy dbconfig that I can populate.
>
> > > > then set up a model, and tell the model to use the newly created (or
> > > > altered) configuration. However, my attempts at this have failed, the
> > > > model always expects a database and table to be present, but when I
> > > > try to change this on the fly using
>
> > > > $this->Dummy->useTable = $info['from'];
> > > > $this->Dummy->useDbConfig="alt";
>
> > > > However, when I try to use this "Dummy" Model through cakes paginator,
> > > > it still tries to see the fields from whatever Dummy Model was set to
> > > > when it was loaded.
>
> > > > I hope one of you can see the predicament that I'm in. I'm looking for
> > > > a solution which only uses the cakephp1.2 (svn) functions - I wouldnt
> > > > be happy using any third party pagination, however using the
> > > > pagination class from the bakery in my cake 1.1 was working to an
> > > > extent.
>
> > > > I guess the best way to describe what I'm trying to achieve is if you
> > > > were trying to recreate phpmyadmin using cake1.2, with its results
> > > > pagination, dynamic database, custom queries etc, but on a lot smaller
> > > > scale, to be able to generate reports based on a database on the fly
> > > > (nothing hard coded)
>
> > > > Many thanks in advance
>
> > > > MIke
>
> > > > --
> > > > ------------------------------------
> > > > Mike Green
>
> > > > Find yourself some misspelled ebay bargains!http://www.typingwand.com
>
> > --
> > ------------------------------------
> > Mike Green
>
> > Find yourself some misspelled ebay bargains!http://www.typingwand.com


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
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