我在YAML配置API中很努力,可以找到here。我用例:Silverstripe 3配置条件
我有2“配置”的属性
class Foo extends Object {
private static $host = null;
private static $port = null;
}
现在我每环境需要不同的主机名称,但相同的端口类。 假设,在dev环境中,$ host应该是1.1.1.1,并且在live环境中ist必须是2.2.2.2。端口应该设置为10000;
---
Name: myexcitingconfig
---
Only:
environment: 'dev'
---
Foo:
host: '1.1.1.1'
port: 10000
---
Only:
environment: 'live'
---
Foo:
host: '2.2.2.2'
port: 10000
---
Bar:
test: 'hooray'
在这个例子中,“富”的所有属性都为空,只有“吧:::
其他所有的部分应为所有类型的env
config.yml
(不工作)是有效的测试“已设置。
Debug::dump(Config::inst()->get('Foo', 'host')); // => null
Debug::dump(Config::inst()->get('Foo', 'port')); // => null
Debug::dump(Config::inst()->get('Bar', 'test')); // => 'hooray'
我在做什么错?
是您的类命名空间? – bummzack
@bummzack:不,不是 – derRobert