I found out that I hate to keep in mind ID of pending status value in statuses table or the other values like that. And actually I had a plugin to resolve this problem which is called sfConstPlugin but as it turned out it’s hard to manage it sometimes especially if you want to provide for the user a way to manage these values EASILY from backend. So here is the answer – new sfAdvancedConstPlugin plugin is ready for publishing but I have not had a chance yet to put it on symfony-project’s pear. Am going to do that on next weekend. So `sfAdvancedConstPlugin` is a symfony plugin that provides app wide constants functionality. It automatically generates constant values based on sfRefTable values and make them accessible in every app module. Values in sfRefTable are simple id/name references tables you have in your system. So effectively you add through sfAdvancedConstAdmin table names like user_status, entity_type, log_type, etc. Then plugin works the following way – system goes through the tables defined in sfRefTable and generate for each id / name pair from this table constants on the fly (via handler mechanism). And now you may use these constants in your code as USER_STATUS_PENDING, LOG_TYPE_ERROR, etc. Of course in order to get access to these constants dont forget to add a line:

include_once (sfConfigCache::getInstance()->checkConfig(‘config/db_advanced_const.yml’));

to index.php or backend.php or another controller/script where you want to have a way to use these values.

This plugin is different from sfConst plugin which required to keep all the constants directly in sfConst table and did not require additional ref tables. Effectively, both plugins are usefull to be used. sfConst is good to go if you want to keep all the constanst centralized.

So for now you may download and try it out from here:

I hope someone will find it usefull, at least it saves a lot for time me now and I dont have to keep in mind all those ID values.

4 replies on “sfAdvancedConstPlugin”

Leave a Reply

Your email address will not be published. Required fields are marked *