Re: [PHP] Having trouble with a multidimensional array menu - new and improved

2009-02-23 Thread Daevid Vincent
Okay, I scrapped my multi-array version and have come up with what seems
to be a cleaner recursive object way of doing this.

The last bit of help I need is in the expandSelectedMenu() part. I need
a way to store all the parent nodes above, then traverse them and set
their CSS class accordingly as per the comment in the code.

//FIXME: so the tricky part is to expand all the directories in the path
to $currentMenuItem
//   we should traverse the ->parent maybe?? and set all
//   goes to
document.getElementById($id).className = "navTree";
//  and (while not required it seems, but is good 
form)
//   
goes to
document.getElementById($id).className = "directory";
//   using the $id = str_replace(array(' ','\
\','-'),'',strtolower($value->menu));

I've tried to do some "$value->parent =& $parent;" but when I var_dump()
I start seeing all these *RECURSION* sections. It seems there should be
a nicer way to store the 'root node' so to speak, and not all the
children and recurse like that. I just can't figure it out.

I know that this probably won't render right for you as you need the CSS
and JS and all that, but I'm happy to share that with anyone that helps
out to get this solved in an elegant way. Also other suggestions and
improvements are welcome. I've attached a screen shot so you can see
what it looks like.
<>
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] Having trouble with a multidimensional array menu

2009-02-18 Thread Jim Lucas

Daevid Vincent wrote:

I'm trying to build a multi-array menu (but open to using classes or
something if that makes this easier).
Does anyone have a solution already working?

I'm very close, but I can't seem to get my "directories" to work and I
end up with extraneous  blocks.

here's what I need to re-create:



Also, just to point out, you have a duplicate ID tag in your code.

Watch out with those.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Having trouble with a multidimensional array menu

2009-02-18 Thread Jim Lucas

Daevid Vincent wrote:

I'm trying to build a multi-array menu (but open to using classes or
something if that makes this easier).
Does anyone have a solution already working?

I'm very close, but I can't seem to get my "directories" to work and I
end up with extraneous  blocks.

here's what I need to re-create:



Try this function instead.

function multiArray2MenuTree( $menu, $indent = 0, $sub = false ) {
  if ( is_array($menu) && count($menu) ) {
print(str_repeat("\t",$indent).'');
foreach ($menu as $key => $value) {
  //echo "$key = $value\n";
  if ( is_array($value) ) {
print(str_repeat("\t",$indent+1).
''.$value['alt'].'');
multiArray2MenuTree($value, $indent+1, true);
print(str_repeat("\t",$indent+1).'');
  } elseif ($key == 'alt' && !$sub) {
print(str_repeat("\t",$indent+1).''.$value['alt'].'');
  } else {
print(str_repeat("\t",$indent+1).'I did not match either if
condition, you need to figure out why...');
  }
}
print(str_repeat("\t",$indent).'');
  }
}

This might point out what is happening.

Now, to fix it.  Use this...

function multiArray2MenuTree( $menu, $indent = 0, $sub = false ) {
  $output = '';
  if ( is_array($menu) && count($menu) ) {
foreach ($menu as $key => $value) {
  if ( is_array($value) ) {
$output .= str_repeat("\t",$indent).''.$value['alt']."";
$output .= multiArray2MenuTree($value, $indent+1, true);
$output .= "\n";
  } elseif ($key == 'alt' && !$sub) {
$output .= str_repeat("\t",$indent).''.$value['alt']."\n";
  }
}
if ( strlen($output) > 0 ) {
  $output = PHP_EOL.str_repeat("\t",$indent).
''.
PHP_EOL.$output.PHP_EOL.
str_repeat("\t",$indent).'';
}
  }
  return $output;
}

echo multiArray2MenuTree($navArray);

Try the above and let us know how it worked.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php