• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Programming Challenge

#11
[eluser]sophistry[/eluser]
why are you storing hierarchical data like that? field names = div block names? that's part of why this is so tricky to get under control - because the starting point is tricky.

why not use the filesystem (designed to represent hierarchy) and just create a directory tree to represent the blocks? then, one call to CI directory_map() gives you a nice array to work with.

sounds like you are designing the whole thing anyway...

cheers.

#12
[eluser]seanloving[/eluser]
Ho hum, a codeigniter weekend...

@helmutbjorg - I made your shit function recursively more shitty. Thanks a lot for the starting point.

Now it is possible to parse an arbitrary array of field names and create the page structure based on the names of the fields (hierarchical naming convention). This helps a new approach to templates I am developing.

Code:
function reformat($regions)
{
    $format = array();
    foreach($regions as $region)
    {
        $region_array = explode('_', $region);
        $region_array = array_reverse( $region_array, true );
        $add = '';
        foreach( $region_array as $reg )
        {
            $add = array( $reg => $add );
        }
        $format = $this->array_merge_recursive_distinct($format,$add);
    }
    return $format;
}

additional credits:
I lifted the function array_merge_recursive_distinct($format,$add) from http://www.php.net/manual/en/function.ar...ursive.php because the standard array_merge_recursive doesn't quite do the trick in PHP5.3

--SL


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.