Yii Framework Forum: Tricky Configuration Setup, Could Use Some Help - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Tricky Configuration Setup, Could Use Some Help Rate Topic: -----

#1 User is offline   danapplegate 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 14-November 12

Posted 14 November 2012 - 12:19 PM

Hi all, I've tried searching the forums but haven't yet found an answer that quite matches my problem.

In our application, we have three levels of config files, or more. main.php is the production environment, qa.php is for pointing our qa environments to our qa database, and dev.php swaps out lots of features for their local or dummy versions. We set up simple inheritance by using CMap::mergeArray(), to have qa.php and dev.php inherit most settings from main.php

Our problem is arising when we try to swap out a different component in dev.php for their main.php counterparts. For example, we have set up memcache in main.php:
return array(
    // application components
    'components' => array(
        'cache' => array(
            'class' => 'CMemCache',
            'servers' => array(
                array(
                    'host' => 'x.x.x.x',
                    'port' => '11211',
                    'weight' => '100',
                )
            )
        )
    )
);


And in dev.php we override that with a CDummyCache, because we don't want to use caching locally:
return array(
    // application components
    'components' => array(
        'cache' => array(
            'class' => 'CDummyCache'
        )
    )
);


We combine the two in our index.php with the following:
// setup config settings
$config = require dirname(__FILE__) . '/protected/config/main.php';
if ($_SERVER['APPLICATION_ENV'] == 'local') {
    $configServer = require dirname(__FILE__) . '/protected/config/dev.php';
    $config = CMap::mergeArray($config, $configServer);
}
$app = Yii::createWebApplication($config)->run();


Because of the recursive nature of the mergeArray method, our final configuration on our local machines ends up with a mishmash of both the main and dev definitions for the cache, with no way to completely override main's definition of the cache component short of unsetting it before we do the merge.

Ultimately, this causes Yii to crash locally, because it tries to create a CDummyCache and then set its 'servers' attribute, which of course isn't defined in CDummyCache.

Any ideas for the best way to solve situations like this?

We're using Yii 1.1.10
0

#2 User is offline   CodeButterfly 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 51
  • Joined: 30-August 12

Posted 14 November 2012 - 02:12 PM

First thing that comes to mind is that your main.config is for config data that is common to all setups. So if memcache isn't common to all your setups don't put it in the common config. Instead put it in a production.config that is specific to the environments where it's relevant.

That said I'd also be interested to hear if there is an easy way to completely override a config section.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users