Subscribed unsubscribe Subscribe Subscribe

@peccul is peccu

(love peccu '(emacs lisp cat outdoor bicycle mac linux coffee))

CakePHPでドメインごとにDBの設定を切り替える

How do I configure CakePHP to detect my development / production environments or do I just keep the config files out of version control? - Stack Overflow

こんな感じにdatabase.phpコンストラクタを追加すると、 ドメインごとにDBの設定を切り替えられるみたいです。 develop、productionとかの切り替えってもうちょっと簡単にできると思ってたのですが。。。

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;
        }
    }
}