
I keep trying to figure out how to reference the sfConfig variables. I also often forget what variables are available to me through the symfony framework. So, for my own benefit and anyone else’s who might be looking for that as well, here it is: as many of the sfConfig variables as I could find. In grabbing all of these I found a few that I never knew existed. Most of these are to aid symfony in finding all of those extra classes you’ve made in your application but they’re still available to you in your application to use however you wish.
Reference to Config Variables
- Be careful in referencing any app-specific variables in the model in a multi-app project. If they are not available in the app you are using the model function in you will have problems.
sfConfig::get('sf_config_variable', 'The default value'); // The default is optional.
Symfony Framework
sf_symfony_lib_dir
The real path to the framework’s lib directory
(/usr/share/php/symfony/symfony12/lib)
Project Structure and Layout
sf_root_dir
The path to the project root
(/var/www/project_name)
sf_apps_dir
The path to the project’s apps folder
(/var/www/project_name/apps)
sf_lib_dir
The path to the project’s lib folder
(/var/www/project_name/lib)
sf_log_dir
The path to the project’s log folder
(/var/www/project_name/log)
sf_data_dir
The path to the project’s data folder
(/var/www/project_name/data)
sf_config_dir
The path to the project’s config folder
(/var/www/project_name/config)
sf_test_dir
The path to the project’s test folder
(/var/www/project_name/test)
sf_doc_dir
The path to the project’s doc folder
(/var/www/project_name/doc)
sf_plugins_dir
The path to the project’s plugins folder
(/var/www/project_name/plugins)
sf_cache_dir
The path to the project’s plugins folder
(/var/www/project_name/cache)
sf_web_dir
The path to the project’s plugins folder
(/var/www/project_name/web)
sf_upload_dir
The path to the project’s upload folder
(/var/www/project_name/web/uploads)
Application Information
sf_app
The current application
(backend)
sf_environment
The current environment
(dev)
sf_debug
Whether debugging is enabled
(1)
Application Structure and Layout
sf_app_dir
The path to the current application
(/var/www/project_name/apps/backend)
sf_app_config_dir
The path to the current application’s config directory
(/var/www/project_name/apps/backend/config)
sf_app_lib_dir
The path to the current application’s lib directory
(/var/www/project_name/apps/backend/lib)
sf_app_module_dir
The path to the current application’s module directory
(/var/www/project_name/apps/backend/modules)
sf_app_template_dir
The path to the current application’s template directory
(/var/www/project_name/apps/backend/templates)
sf_app_i18n_dir
The path to the current application’s i18n directory
(/var/www/project_name/apps/backend/i18n)
Cache Structure and Layout
sf_app_base_cache_dir
The path to the current application’s directory in the cache
(/var/www/project_name/cache/backend)
sf_app_cache_dir
The path to the current application’s directory in the cache by current environment
(/var/www/project_name/cache/backend/dev)
sf_template_cache_dir
The path to the current application’s templates directory in the cache by current environment
(/var/www/project_name/cache/backend/dev/template)
sf_i18n_cache_dir
The path to the current application’s i18n directory in the cache by current environment
(/var/www/project_name/cache/backend/dev/i18n)
sf_config_cache_dir
The path to the current application’s config directory in the cache by current environment
(/var/www/project_name/cache/backend/dev/config)
sf_test_cache_dir
The path to the current application’s test directory in the cache by current environment
(/var/www/project_name/cache/backend/dev/test)
sf_module_cache_dir
The path to the current application’s modules directory in the cache by current environment
(/var/www/project_name/cache/backend/dev/modules)
Application Settings
You can access any value in settings.yml by prepending “sf_” to the value.
sf_error_404_module
The module that contains the 404 action (default)
sf_error_404_action
The action that displays the 404 error (error404)
sf_logging_enabled
Boolean for whether logging is currently enabled (1)
sf_escaping_strategy
Whether the sfView class is using the Escaping Strategy (1)
sf_no_script_name
Whether the application is requiring the script name. (1)
sf_csrf_secret
The CSRF secret (UniqueSecret)
Also:
You can grab some information from the current context (usually in templates, but should work well enough in actions – I’d be very cautious about using these in models):
sfContext::getInstance()->getActionName();
The name of the current action. Can also be called by $this->getActionName() in templates.
(my_awesome_action)
sfContext::getInstance()->getModuleName();
The name of the current module. Can also be called by $this->getModuleName() in templates.
(my_awesome_module)
sfContext::getInstance()->getModuleDirectory();
The path to the current module’s directory
(/var/www/project_name/apps/backend/modules/my_awesome_module)
Tags: symfony, web development
This entry was posted on Tuesday, June 2nd, 2009 at 6:37 pm by NoCoolName_Tom and is filed under symfony Framework. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Handy reference.. thanks for writing it up.
[...] Doggetto.com : Blog : Symfony sfConfig Variables [...]
So, um, yeah for anyone who is visiting I’m still learning this stuff. You can get a list of ALL sfConfig variables just by using the sfWebDebug Toolbar >> “config” >> Settings.
So, yeah, that was rather dumb of me. STILL, at least now I know.
Well I didn’t know about the config variables or the toolbar, so this was really useful for me – thanks!