Combining arrays

Good day!

It has long been trying to solve their problem: I have the basic configuration is the site configs modules, i.e. I want to connect the module and configuration module that automatically connects to the system. In the lessons described this method: http://www.yiiframew…oc/cookbook/32/ but it does not fit me because it is known in advance how many will be configuration, but in my case is not known, and I use this code in conf_hard.php (this is main config file):


$modules = CommonTools::findModules();

foreach($modules['conf'] as $module)


   require_once('./protected/modules/' . $module . '/conf_' . $module . '.php');


$conf_hard = array(...);

return $conf_hard;

Actually the question is how to combine these arrays are connected to the main configuration file, if we did not know how many of them would be?

$mainConfig=...main config...

foreach($moduleConfigs as $moduleConfig)

    $mainConfig=CMap::mergeArray($mainConfig, $moduleConfig);

return $mainConfig;

Unfortunately, such an approach, I get an error:

Property “CWebApplication.urlManager” is read only.  :(


I use both urlManager configuration file, because each module to configure how.

help me plz  :)

Why combining array would cause such an error? What arrays are you combining?

Perhaps the problem is that basically there is a config urlManager in the config module too. It complements the basic rules.

I will combine the basic configuration with a configuration of module.

Nono, my question is: why combining arrays would cause setting CWebApplication.urlManager? It should be pure array manipulation. Why would it involve CWebApplication object here?

Maybe I misunderstand, but the array urlManager sets the basic rules of uri, but in the configuration of modules urlManager sets the path for this specific module.

In this, my main problem, it is desirable that all uri rules comes with the module itself, so to me and should have urlManager in one config and in the other.

Sorry for the concern, no ideas? : (

help me  :(

For URL rules, they should be put in the same place, or at least, there is a central place to aggregate the rules scattered in other places. The reason is that when parsing URLs, Yii needs to have the complete list of URL rules so that it can identify which rule to apply.

For your problem, you may consider in your main app config, add:

where urlRules.php is responsible to aggregate all module URL rules into a single big array.

that is, do you suggest I use a separate configuration with UrlRules?

what the contents of this file in my case? All the rules for all the modules or something else?

urlRules.php could be as simple as returning an array of URL rules.

In your case, since you want to let each module has its own URL rule set, you may store each module rule set in a separate file, and then write a piece of code in urlRules.php to combine them and return them as a single array of rules.

ooo its worked! Thanx a lot!  ;)