symfony cheat sheet

In an action: set a template variable using disabled output escaping

 $this->setVar('foo', '<b>important</b>', true);

Get the current environment

sfConfig::get('sf_environment')

Get a settings.yml variable

sfConfig::get('sf_enabled_modules')

 Get a param in the view

$sf_params->get('total')

Get a raw param in the view

$test = $sf_data->getRaw('test');

Disable Webdeveloper Toolbar

sfConfig::set('sf_web_debug', false);

Use Helper in Action

$this->getContext()->getInstance()->getConfiguration()->loadHelpers(array('Url'));

 

 sfFinder

          <?php $images = sfFinder::type('file')
            ->name('*.jpg')
            ->sort_by_name()
            ->in(sfConfig::get('sf_web_dir') . '/images/slider')
          ?>

sfConfig

paths

sf_root_dir           # myproject/
sf_apps_dir           #   apps/
sf_app_dir            #     frontend/
sf_app_config_dir     #       config/
sf_app_i18n_dir       #       i18n/
sf_app_lib_dir        #       lib/
sf_app_module_dir     #       modules/
sf_app_template_dir   #       templates/
sf_cache_dir          #   cache/
sf_app_base_cache_dir #     frontend/
sf_app_cache_dir      #       prod/
sf_template_cache_dir #         templates/
sf_i18n_cache_dir     #         i18n/
sf_config_cache_dir   #         config/
sf_test_cache_dir     #         test/
sf_module_cache_dir   #         modules/
sf_config_dir         #   config/
sf_data_dir           #   data/
sf_lib_dir            #   lib/
sf_log_dir            #   log/
sf_test_dir           #   test/
sf_plugins_dir        #   plugins/
sf_web_dir            #   web/
sf_upload_dir         #     uploads/

i18n Date Formats

For an explanation of the cryptic patterns @see sfDateFormat::getPattern(), sfDateFormat::$tokens

The number of letters adjust the rendered "length". Example:

  • format_date('2016-04-14, 'M y') -> 4 2016
  • format_date('2016-04-14, 'MM y') -> 04 2016
  • format_date('2016-04-14, 'MMM y') -> Mar 2016
  • format_date('2016-04-14, 'MMMM y') -> March 2016

tokens

  •     'G' => 'Era',
        'y' => 'year',
        'M' => 'mon',
        'd' => 'mday',
        'h' => 'Hour12',
        'H' => 'hours',
        'm' => 'minutes',
        's' => 'seconds',
        'E' => 'wday',
        'D' => 'yday',
        'F' => 'DayInMonth',
        'w' => 'WeekInYear',
        'W' => 'WeekInMonth',
        'a' => 'AMPM',
        'k' => 'HourInDay',
        'K' => 'HourInAMPM',
        'z' => 'TimeZone'