0
我想從config.yml中取出symfony2實體中的值。從實體中獲取config.yml值
config.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
有一個其他的解決方案是一個不錯的主意:http://dev4theweb.blogspot.ch/2012/08/how-to-access -configuration-values.html – Ueli
它和sfConfig是symfony1一樣好。單例模式打破了良好的可測性。 – Florian