What is the best way to access lookup values in symfony? On the database or constants?
I am creating a web project 开发者_如何转开发and want it to be optimized. Instead of accessing lookup values in the database (to minimize access), I think it should be stored somewhere in symfony. What is the best way to this? In YML with PHP Array?
You can put values that don't change often in lib/app.yml
You can access those values by using sfConfig::get('value').
app.yml is cool because you can store enviroment specific values in it.
Another option I use for values that should never change and that are not environment-specific is to define constants in a relevant model or helper class.
The advantages are:
1) if you name those constants well using them helps make the code more self-documenting
2) if you use an IDE with autocompletion features it will look up and verify their names as you're coding.
3) they are the fastest possible method of lookup.
精彩评论