2

I'm using F3 (Fat-Free Framework) for a project at work and have stumbled across a problem I can't seem to find any information about. Neither Google nor official F3 documentation has given me anything. Maybe I'm simply asking the wrong question. Here's the problem.

I have an array that looks something like this: ( city => type => building )

$places = array(
    'City A' => array(
        'special' => array(),
        'standard' => array('Campus', ),
    ),
    'City B' => array(
        'special' => array(
            'collect',
            'exam',
            'Brännässlan',
        ),
        'standard' => array(
            'Building A',
            'Building B',
            'Building C',
            'Building D (Library)',
            'Capitol',
            'Flair',
        ),
    ),
),

What I want to do is to check each building in the array to see if a corresponding dictionary variable has been set for it. I use $f3->exists('dict_select_hus_arrayValue') to check and it works fine until the function encounters a building with the letter 'ä' in it. If it does, it throws a 500 error with the text Invalid hive key 'dict_select_hus_Brännässlan'.

I assume it has to do with the encoding of the string, but I work in a purely UTF-8 environment and F3 should be able to handle it. Has anyone else encountered this and, more importantly, found a solution to the problem?

Szandor
  • 363
  • 1
  • 12

2 Answers2

5

F3 doesn't allow language specific characters to be used as keys in hive. I'm not sure if this was intended or accidental, but the root cause of this problem lies in &ref method of Base class. You will find somewhere around line 244 a preg_match('/^\w+$/',$parts[0]). This will return false in your case as language specific characters are not within \w.

My advice would be to either change this expression to include chars like the ones you use (you will need to remember about this modification in case you will later upgrade F3 or reset it for some reason) or strip the string of them before checking with F3.

george007
  • 609
  • 1
  • 7
  • 18
5

It's true that a hive key is not allowed to have special chars, as @george007 has discovered. But this only applies for the very first hive key segment $part[0]. It's free to use it one level deeper. So city.Brännässlan should be fine. Just put your cities and dictonary entries into a deeper level. i.e:

$f3->set('places',$places);

lang file:

dict.select_hus.Brännässlan = XY
dict.select_hus.Kairo = YZ

php:

foreach ($f3->get('places') as $c_name => $city) {
  if ($f3->exists('dict.select_hus.'.$c_name)) {
    // it's there
  }
}

One NB from http://fatfreeframework.com/base#set

Remember: Hive keys are case-sensitive. Furthermore, root hive keys are checked for validity against these allowed chars: [ a-z A-Z 0-9 _ ]

ikkez
  • 2,052
  • 11
  • 20