Re: Change database of models

2009-02-17 Thread Dr. Loboto

You can try this way after database name retrieve:

// Copy default config values, usefull if dynamic config differs only
in one-two params
$config = $this-getDataSource()-config;
// Set new database name
$config['database'] = $target_database_name;
// Add new config to connections manager
ConnectionManager::getInstance()-create('nameForNewConfig', $config);
// Point model to new config
$this-useDbConfig = 'nameForNewConfig';

$this in this case is model. So intially your dynamic models points
to default database and you switch connection in runtime.

On Feb 16, 4:51 pm, Henrik Gemal henrikge...@gmail.com wrote:
 what should I set as the default useDbConfig in my model?

 Say I have a model called x. This model is located in database which
 I dont know the name of when loading the model uses uses

 I first know the database name after I query the first name where I
 get the name of the database.

 So should I create a dummy database config? or set it to something
 like false?

 On Feb 13, 11:08 pm, LunarDraco mdc...@gmail.com wrote:

  There is a property which is part of model called $useDbConfig.
  From a controller you can call or set it like:
  $this-model-setSource('mydbConfig');
  To get the current model dbConfig call
  currentconfig = $this-model-getDataSource();

  If your storing your config info in database1. you would build up your
  default config to point at this database.
  in your appcontroller or your appmodel you make use of your dbconfig
  model and query for the specific model.

  I suppose your dbconfig schema would have fields that match up to the
  database.php config array
  array(
  'driver' = 'mysql',
  'persistent' = false,
  'host' = SANDBOX_DB_HOST,
  'port' = '',
  'login' = SANDBOX_DB_USERNAME,
  'password' = SANDBOX_DB_PASSWORD,
  'database' = SANDBOX_DB_NAME,
  'schema' = '',
  'prefix' = '',
  'encoding' = ''
  );
  With some additional fields based on how you want to find the
  dbconfig. Based on your request I'd say at least Model.
  your query would do a findbymodel to retreive the info.
  You would then need to replace the assigned var $customdb in the
  DATABASE_CONFIG class.
  once you've done that you can set or assign the configuration to each
  model.

  One question what is the reason for storing the connection info in a
  database?
  if you only have a few connections you could easily add multiple
  config arrays to the database_config in app\config\database.php and
  just switch them out using the $this-model-setSource
  ('config_var_name');
--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Change database of models

2009-02-16 Thread Henrik Gemal

what should I set as the default useDbConfig in my model?

Say I have a model called x. This model is located in database which
I dont know the name of when loading the model uses uses

I first know the database name after I query the first name where I
get the name of the database.

So should I create a dummy database config? or set it to something
like false?

On Feb 13, 11:08 pm, LunarDraco mdc...@gmail.com wrote:
 There is a property which is part of model called $useDbConfig.
 From a controller you can call or set it like:
 $this-model-setSource('mydbConfig');
 To get the current model dbConfig call
 currentconfig = $this-model-getDataSource();

 If your storing your config info in database1. you would build up your
 default config to point at this database.
 in your appcontroller or your appmodel you make use of your dbconfig
 model and query for the specific model.

 I suppose your dbconfig schema would have fields that match up to the
 database.php config array
 array(
 'driver' = 'mysql',
 'persistent' = false,
 'host' = SANDBOX_DB_HOST,
 'port' = '',
 'login' = SANDBOX_DB_USERNAME,
 'password' = SANDBOX_DB_PASSWORD,
 'database' = SANDBOX_DB_NAME,
 'schema' = '',
 'prefix' = '',
 'encoding' = ''
 );
 With some additional fields based on how you want to find the
 dbconfig. Based on your request I'd say at least Model.
 your query would do a findbymodel to retreive the info.
 You would then need to replace the assigned var $customdb in the
 DATABASE_CONFIG class.
 once you've done that you can set or assign the configuration to each
 model.

 One question what is the reason for storing the connection info in a
 database?
 if you only have a few connections you could easily add multiple
 config arrays to the database_config in app\config\database.php and
 just switch them out using the $this-model-setSource
 ('config_var_name');
--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Change database of models

2009-02-16 Thread AD7six



On Feb 16, 11:51 am, Henrik Gemal henrikge...@gmail.com wrote:
 what should I set as the default useDbConfig in my model?

 Say I have a model called x. This model is located in database which
 I dont know the name of when loading the model uses uses

 I first know the database name after I query the first name where I
 get the name of the database.

 So should I create a dummy database config? or set it to something
 like false?

You probably need to either set useDbConfig = $x; where $x is a db
config you can always connect to and has the table for the model your
loading OR useTable = false.

Alternatively look at the model.php code and look for what you need to
override, hard to say anything else given you gave no reasoning for
why you're doing what you're doing.

hth,

AD
--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Change database of models

2009-02-13 Thread Henrik Gemal

In my controller I first need to query a database which holds
information about which database all of the models should use. I'm not
sure how to do this.

When the models get initialized by the uses array I haven't yet
determined what database they should use.

Any clue in which direction I should look?
--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Change database of models

2009-02-13 Thread LunarDraco

There is a property which is part of model called $useDbConfig.
From a controller you can call or set it like:
$this-model-setSource('mydbConfig');
To get the current model dbConfig call
currentconfig = $this-model-getDataSource();

If your storing your config info in database1. you would build up your
default config to point at this database.
in your appcontroller or your appmodel you make use of your dbconfig
model and query for the specific model.

I suppose your dbconfig schema would have fields that match up to the
database.php config array
array(
'driver' = 'mysql',
'persistent' = false,
'host' = SANDBOX_DB_HOST,
'port' = '',
'login' = SANDBOX_DB_USERNAME,
'password' = SANDBOX_DB_PASSWORD,
'database' = SANDBOX_DB_NAME,
'schema' = '',
'prefix' = '',
'encoding' = ''
);
With some additional fields based on how you want to find the
dbconfig. Based on your request I'd say at least Model.
your query would do a findbymodel to retreive the info.
You would then need to replace the assigned var $customdb in the
DATABASE_CONFIG class.
once you've done that you can set or assign the configuration to each
model.

One question what is the reason for storing the connection info in a
database?
if you only have a few connections you could easily add multiple
config arrays to the database_config in app\config\database.php and
just switch them out using the $this-model-setSource
('config_var_name');

--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---