Tuesday, September 29, 2009

Multiple Databases, Database Switching in CAKEPHP

This is a small tip but more powerfu l and useful tweak for the developers who will often change the database configuration details while moving to developement environment to live env and vice versa.

<?php
class DATABASE_CONFIG {
var $development = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'port' => '',
'login' => 'your_local_username',
'password' => 'your_local_password',
'database' => 'your_local_database',
'schema' => '',
'prefix' => '',
'encoding' => ''
);
var $production = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'your_remote_server',
'port' => '',
'login' => 'your_remote_username',
'password' => 'your_remote_password',
'database' => 'your_remote_database',
'schema' => '',
'prefix' => '',
'encoding' => ''
);
var $default = array();
function __construct(){
$this->default = ($_SERVER['SERVER_ADDR'] == '127.0.0.1') ? $this->development : $this->production;
}
function DATABASE_CONFIG(){
$this-> __construct();
}
}
?>


By the above script you can automatically switch your datbases according to the server.
And one more useful tip
we often used to change the value of debug constant in core.php file Right.... ?
Below is the small tip for that. By this, debug will be set to zero automatically
in live environment and it will be set to '2' in the development environment.
In app/core.php replace with following code :

FIND:

Configure::write('debug',2);

REPLACE WITH :

if($_SERVER['SERVER_ADDR'] == '127.0.0.1'){
Configure::write('debug', 2);
}else{
Configure::write('debug', 0);
}

Labels: , , , ,

posted by adityachandra @ 11:18 PM, ,


Tuesday, February 10, 2009

Coping with CakePHP

Recently I have moved to a new company EYANTRA. It provides brand merchandising solutions to corporates. Here we have a team of 6 members including me. The framework we are using is Cake PHP (?). All the other five are working with cake php for the past few months. So I have started learning cake php after joining here.

Already I have experience with PHP frame works like PHPMVC, TinyMVC, and CodeIgniter. One best thing i came across in cake php is in built support for Ajax. Cake PHP has built in helper classes for Ajax using prototype frame work. Other useful helpers are HTML,Session and the most famous helper Paginator.

I hope that i will be expert in this framework very soon. Keep watching this space for more articles on Cake PHP.

Labels:

posted by adityachandra @ 1:56 PM, ,