UBB.Dev
Posted By: Gardener Config options with arrays - 05/12/2003 4:14 AM
I want to put in an array as value of a config option, but this seems to muck up the editconfig script as it shows 'Array' as value instead of the array. Any ideas how to get around this? I really want an associative array for easy access.

At the moment it looks like this:
Code
$config['groupcolor'] = array(<br />    "5" => "Normal",<br />    "6" => "#FF6600",<br />    );<br />


Or is this something I should report as a bug?
Posted By: Dave_L_dup1 Re: Config options with arrays - 05/12/2003 4:20 AM
I would be surprised if the config editor could handle that. I think it treats all the $config values as scalars.
Posted By: JoshPet Re: Config options with arrays - 05/12/2003 4:21 AM
OOH - I dunno the answer - but I kind of like your theory about it... colors for groups.

Can something like this work?

$config['groupcolor'][5] =
Posted By: Gardener Re: Config options with arrays - 05/12/2003 4:23 AM
Yeah, I could do it that way I guess. A bit more to write though, but that shouldn't matter. Thanks.

I've been doing a mod on request to change color and/or title based on group which I will be able to release soon for your enjoyment.
Posted By: Gardener Re: Config options with arrays - 05/12/2003 4:26 AM
It seems I spoke to soon, since that notation also gives an array, the same problem arises.

I really don't want to have a comma separated value and split it, it's not very clean and easy to break.
Posted By: Gardener Re: Config options with arrays - 05/12/2003 4:43 AM
No, it seems it doesn't, but here is a quick hack to make it handle one level of arrays.

Change these lines in admin/editconfig.php:
Code
<br />   while (list($key,$value) = each($config)) {<br />      if (!ereg("-$key-",$knownkeys)) {<br />         $extras .= "\$config['$key'] = '$config[$key]';\n";<br />      }<br />   }<br />


To this:
Code
<br />   while (list($key,$value) = each($config)) {<br />      if (!ereg("-$key-",$knownkeys)) {<br />          if ( is_array($config[$key]) ) {<br />              $printvalue = "array(";<br />              while (list($akey,$aval) = each($config[$key])) {<br />                  $printvalue .= "'$akey' => \"$aval\",\n";<br />              }<br />              $printvalue .= ")";<br />          } else {<br />              $printvalue = "'$config[$key]'";<br />          }<br />         $extras .= "\$config['$key'] =	$printvalue;\n";<br />      }<br />   }<br />
Posted By: Dave_L_dup1 Re: Config options with arrays - 05/12/2003 4:46 AM
You might try something like:

Code
$config['groupcolor'] = "array(<br />    '5' => 'Normal',<br />    '6' => '#FF6600',<br />    )";


and then do an eval. But the config editor might get confused by the nested quotes.
Posted By: Gardener Re: Config options with arrays - 05/12/2003 4:48 AM
I'll give that a shot.
Posted By: Gardener Re: Config options with arrays - 05/12/2003 4:59 AM
Thanks, that did the trick, without having to hack admin/editconfig.php.

Here's how I did, I put this in the config file:
Code
$config['groupcolor'] =	'array("5" => "Normal",<br />"6" => "#FF6600",<br />)';<br />

And did this in the script to get the array:
Code
   eval("\$groupcolor = {$config['groupcolor']};");<br />


That works, but if one quotation mark is wrong it can break the editconfig page.
© UBB.Developers