Doggetto.com

June 2, 2009

Symfony sfConfig Variables

Filed under: symfony Framework — Tags: , — NoCoolName_Tom @ 6:37 pm

Variables

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)

6 Comments »

  1. Handy reference.. thanks for writing it up.

    Comment by Erik — July 14, 2009 @ 3:57 pm

  2. [...] Doggetto.com : Blog : Symfony sfConfig Variables [...]

    Pingback by Daily Digest for 2009-09-30 | Pedro Trindade — October 1, 2009 @ 2:10 am

  3. 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.

    Comment by NoCoolName_Tom — October 1, 2009 @ 10:02 am

  4. Well I didn’t know about the config variables or the toolbar, so this was really useful for me – thanks!

    Comment by Nick Giles — May 28, 2010 @ 4:30 am

  5. It is very interesting tutorial for the symfony biggners

    Comment by surya kant — January 11, 2011 @ 9:49 am

  6. I’m using symfony for nearly 2 months, and i found many new ‘sf’ to me here. Thanks. Also you can create your own by a custom function in ProjectConfiguration.class.php file as =>
    public function setWebDir($webDir){
    sfConfig::set(‘sf_my_new_dir’, $webDir. DIRECTORY_SEPERATOR.’uploads’.DIRECTORY_SEPERATOR.’resume’);
    }//end
    you can set(like above) or add(for array) or clear(for dejecte entire sf) or get(set and get) or has(to check).
    .

    Comment by Sudhakar — April 19, 2011 @ 3:50 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress