I am a RoR developer, but I am presently working with CakePHP for a project where I cannot tweak the server. In my Rails production server, Passenger is setup to automatically use the "Production" environment, overriding the local app setup. I would like to setup my cakephp app to do the same thing. How do you usually accomplish that with CakePHP? Do you set up a domain parser, or you just keep core.php and database.php out of version control? Thanks in advance, Davide
If I understood the question correctly, this might be the thing you need:
Automatically choose database connections in CakePHP
Briefly, override the DATABASE_CONFIG
constructor:
class DATABASE_CONFIG
{
//initalize variable as null
var $default=null;
//set up connection details to use in Live production server
var $prod =
array(
// ...
);
// and details to use on your local machine for testing and development
var $dev =
array(
// ...
);
function __construct ()
{
if(isset($_SERVER['SERVER_NAME'])){
switch($_SERVER['SERVER_NAME']){
case 'digbiz.localhost':
$this->default = $this->dev;
break;
case 'digbiz.example.com':
$this->default = $this->prod;
break;
}
}
else // we are likely baking, use our local db
{
$this->default = $this->dev;
}
}
}
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