kronoszx
7/13/2017 - 4:25 PM

Global Variables

Global Variables

I agree with the solution from @olivierw.

For a personal project, I have a table called Config and I load the content using filter, so I can have access anywhere in my project.

The filter lib/filter/configFilter.php:

<?php

class configFilter extends sfFilter
{
  public function execute ($filterChain)
  {
    // get the config
    $configs = Doctrine_Core::getTable('Config')>findAll();

    foreach($configs as $config)
    {
      sfConfig::set('my_config_'.$config->getName(), $config->getContent());
    }

    // execute next filter
    $filterChain->execute();
  }
}
In apps/frontend/config/filters.yml:

rendering: ~

configFilter:
  class: configFilter

security:  ~
Now you can access any information using:

sfConfig::get('my_config_key');
The schema.yml for my Config table:

Config:
  columns:
    name:     { type: string(255) }
    content:  { type: string(1000) }