I am using CakePHP 1.3 with two data sources:
master defaultHow can I change the data source for a whole function i.e. from default to master for that function.
If I use this
$this->{Model}->setDataSource('master');
it only changes for that model.
Is there any general way???
OK. Try doing something like this. I tried it in newer version of cake and its worked.
in your app model have a function
public function getDataSource(){
$dataSource = Configure::read('currentDataSource');
if($dataSource && $dataSource !== $this->useDbConfig){
$this->setDataSource($dataSource);
}
return parent::getDataSource();
}
Then in your controller , based which data source needed write it in configure.
Configure::write('currentDataSource', 'yourDbsource');
Then call to any of your models.
Dont forget to specify default one from bootstrap.php.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With