Jenski

Jenski's Corner of the Web

Sitewide Config Variables

CakePHP's Configure class is useful to store application settings that you may need throughout your site / web app.

  1. add this line to app/config/bootstrap.php: Configure::load('config');
  2. Create a file named app/config/config.php with all application specific settings $config['Settings'] = array(
    'version' => '1.0.213',
    'title' => 'My Application' );
  3. These settings can be accessed by doing something like:$title = Configure::read('Settings.title');

NOTE: always consider that someone else has already defined a setting with the same category you are specifying. So? Because CakePHP 1.2 is moving all its settings to a Configure approach, and its already utilizing some configuration categories that you may be using, like App. In fact, if you just define a new App category, it will overwrite CakePHP's built in App category and result in your application not working as expected. So instead, define each category like this:

$config['Settings'] = Configure::read('Settings');
$config['Settings'] = Set::merge(ife(empty($config['Settings']), array(), $config['Settings']), array( 'version' => '1.0.213', 'title' => 'My Application' ));

This way we are making sure that if there are settings already defined in that category, we add our own to it instead of overwriting it entirely.

Technique found at: Using Configure On Your CakePHP Application