How to switch config files

14 views
Skip to first unread message

Kristi Wright

unread,
May 19, 2011, 5:51:43 PM5/19/11
to Alloy
I'm impressed with Alloy 0.7.3b and am considering using it for a
project later this year. I see that Alloy lets you load host-specific
config files. I run my development and staging environments from
different ports on the same host and I need different config files for
each. What's the best way to do that?

Vance Lucas

unread,
May 19, 2011, 7:11:09 PM5/19/11
to allo...@googlegroups.com
The current config does not take ports into account - just the network hostname. I would recommend putting some logic in your PHP config file that includes other config files or sets other config values based on the port.

Something like:
# app/config/<hostname>/app.php

$port = $_SERVER['SERVER_PORT'];
if('80' == $port) {
    return require 'development.php';
} elseif('81' == $port) {
    return require 'production.php';
}

Edge cases like these are exactly why I like to keep all config and routing in PHP instead of XML, YAML, INI, or any other format. With PHP, it's fairly easy to come up with a workaround for a missing feature :).

Hope that helps!

--
Vance Lucas
http://vancelucas.com
Reply all
Reply to author
Forward
0 new messages