我想从 symfony2 实体中获取 config.yml 的值。
配置.yml:
my_example_bundle:
slug_pattern: "/^[a-z0-9\._\-]{2,20}$/"
实体:
function setUsername($username) {
$pattern = ""; // need to get it from slug_pattern in config.yml
if (!preg_match($pattern, $username)) {
throw new \InvalidArgumentException("Username has to match " . $pattern);
}
...
}
谢谢!
更新: Dev4TheWeb 也发布了一个不错的解决方案:http ://dev4theweb.blogspot.ch/2012/08/how-to-access-configuration-values.html