Having trouble with a multidimensional array menu

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <ul> blocks.

here's what I need to re-create:

<div class = "portlet nav closed">
	<div class="header"><h2>Admin</h2></div>
	<div class="content">
		<ul class="navTree">

			<li class="directory collapsed"><a href="" class="toggle">Users</a>
				<ul  class="navTree toggleClosed">
					<li class="file ext_txt"><a href="operators">Roles</a></li>
					<li class="file ext_txt"><a href="operators">Report</a></li>
				</ul>
			</li>

			<li class="directory collapsed"><a href=""
class="toggle">Aircraft</a>
				<ul  class="navTree toggleClosed">
					<li class="file ext_txt"><a href="operators">Admin</a></li>
					<li class="file ext_txt"><a href="operators">Search</a></li>
					<li class="file ext_txt"><a href="operators">Audit</a></li>
				</ul>
			</li>

			<li class="directory collapsed"><a href="" class="toggle">Data</a>
				<ul  class="navTree toggleClosed">
					<li class="file ext_txt"><a
href="operators">Airline/Aircraft</a></li>
					<li class="directory collapsed"><a href="" class="toggle">Fault
Logs</a>
						<ul  class="navTree toggleClosed">
							<li class="file ext_txt"><a href="operators">Daily</a></li>
							<li class="file ext_txt"><a href="operators">One Day</a></li>
						</ul>
					</li>
					<li class="file ext_txt"><a href="operators">Duplicate Fault
Log</a></li>
				</ul>
			</li>

			<li class="file ext_txt"><a href="operators">News</a></li>

		</ul>
	</div>
</div>

Here's my array (basically):

$navArray['admin'] = array ('alt' => 'Administration',
							 'title' => 'Administration',
							 'description' => 'Administration Tools and Links',
							 'headline' => true,
							 'users' => array ('alt' => 'Users',
												  'title' => 'Users',
												  'description' => 'Users',
												  'panasonic_only' => true),
							 'aircraft' => array ('alt' => 'Aircraft',
												  'title' => 'Aircraft',
												  'description' => 'Aircraft',
												  'panasonic_only' => true),
							 'logs' => array ('alt' => 'Fault Logs',
												  'title' => 'Fault Logs',
												  'description' => 'Fault Logs',
												  'panasonic_only' => true),
							 'airline' => array ('alt' => 'Airline/Aircraft',
												  'title' => 'Airline/Aircraft',
												  'description' => 'Airline/Aircraft',
												  'page' => 'XXXXX.php',
												  'panasonic_only' => true),
							 'news' => array ('alt' => 'News',
												  'title' => 'News',
												  'description' => 'News',
												  'page' => 'XXXXX.php',
												  'panasonic_only' => true)
);

$navArray['admin']['users']['roles'] =  array ('alt' => 'Roles',
											  'title' => 'Roles',
											  'description' => 'Roles',
											  'page' => 'XXXXX.php',
											  'panasonic_only' => true);
$navArray['admin']['users']['report'] =  array ('alt' => 'Report',
											  'title' => 'Report',
											  'description' => 'Report',
											  'page' => 'XXXXX.php',
											  'panasonic_only' => true);

$navArray['admin']['aircraft']['admin'] =  array ('alt' => 'Admin',
											  'title' => 'Admin',
											  'description' => 'Admin',
											  'page' => 'XXXXX.php',
											  'panasonic_only' => true);
$navArray['admin']['aircraft']['search'] =  array ('alt' => 'Search',
											  'title' => 'Search',
											  'description' => 'Search',
											  'page' => 'XXXXX.php',
											  'panasonic_only' => true);
$navArray['admin']['aircraft']['audit'] =  array ('alt' => 'Audit',
											  'title' => 'Audit',
											  'description' => 'Audit',
											  'page' => 'XXXXX.php',
											  'panasonic_only' => true);

$navArray['admin']['logs']['daily'] =  array ('alt' => 'Daily',
											  'title' => 'Daily',
											  'description' => 'Daily',
											  'page' => 'XXXXX.php',
											  'panasonic_only' => true);
$navArray['admin']['logs']['day'] =  array ('alt' => 'One Day',
											  'title' => 'One Day',
											  'description' => 'One Day',
											  'page' => 'XXXXX.php',
											  'panasonic_only' => true);
$navArray['admin']['logs']['dupes'] =  array ('alt' => 'Duplicate
Faults',
											  'title' => 'Duplicate Faults',
											  'description' => 'Duplicate Faults',
											  'page' => 'XXXXX.php',
											  'panasonic_only' => true);

And here's my recursive function:

function multiArray2MenuTree( $menu, $indent = 0, $sub = false )
{
    if (!is_array($menu)) return false;

    echo str_repeat("\t",$indent)."   <ul class=\"navTree toggleClosed
\">\n";
    foreach ($menu as $key => $value)
    {
    	//echo "<b>$key</b> = $value<br/>\n";

		if (is_array($value))
        {
            echo str_repeat("\t",$indent+1).'<li id="'.$key.'"
class="file ext_txt"><a
href="'.$value['page'].'">'.$value['alt']."</a>\n";
            echo multiArray2MenuTree($value, $indent+1, true);
            echo str_repeat("\t",$indent+1)."</li>\n";
        }
        elseif ($key == 'alt' && !$sub)
           echo str_repeat("\t",$indent+1).'<li id="'.$key.'"
class="directory collapsed"><a href="#"
class="toggle">'.$value['alt']."</a></li>\n";
    }
    echo str_repeat("\t",$indent)."   </ul>\n";
}

multiArray2MenuTree($navArray);

and the output of that:

	<li id="admin" class="file ext_txt"><a href="">Administration</a>
	   <ul class="navTree toggleClosed">
		<li id="users" class="file ext_txt"><a href="">Users</a>
		   <ul class="navTree toggleClosed">
			<li id="roles" class="file ext_txt"><a href="XXXXX.php">Roles</a>
			   <ul class="navTree toggleClosed">
			   </ul>
			</li>
			<li id="report" class="file ext_txt"><a href="XXXXX.php">Report</a>
			   <ul class="navTree toggleClosed">
			   </ul>
			</li>
		   </ul>
		</li>
		<li id="aircraft" class="file ext_txt"><a href="">Aircraft</a>
		   <ul class="navTree toggleClosed">
			<li id="admin" class="file ext_txt"><a href="XXXXX.php">Admin</a>
			   <ul class="navTree toggleClosed">
			   </ul>
			</li>
			<li id="search" class="file ext_txt"><a href="XXXXX.php">Search</a>
			   <ul class="navTree toggleClosed">
			   </ul>
			</li>
			<li id="audit" class="file ext_txt"><a href="XXXXX.php">Audit</a>
			   <ul class="navTree toggleClosed">
			   </ul>
			</li>
		   </ul>
		</li>
		<li id="logs" class="file ext_txt"><a href="">Fault Logs</a>
		   <ul class="navTree toggleClosed">
			<li id="daily" class="file ext_txt"><a href="XXXXX.php">Daily</a>
			   <ul class="navTree toggleClosed">
			   </ul>
			</li>
			<li id="day" class="file ext_txt"><a href="XXXXX.php">One Day</a>
			   <ul class="navTree toggleClosed">
			   </ul>
			</li>
			<li id="dupes" class="file ext_txt"><a href="XXXXX.php">Duplicate
Faults</a>
			   <ul class="navTree toggleClosed">
			   </ul>
			</li>
		   </ul>
		</li>
		<li id="airline" class="file ext_txt"><a
href="XXXXX.php">Airline/Aircraft</a>
		   <ul class="navTree toggleClosed">
		   </ul>
		</li>
		<li id="news" class="file ext_txt"><a href="XXXXX.php">News</a>
		   <ul class="navTree toggleClosed">
		   </ul>
		</li>
	   </ul>
	</li>


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux