[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] PHP flerdimensionel array "udfordring".



On 13/04/2010, at 21.26, Jesper K. Pedersen wrote:

> I forbindelse med et lille projekt jeg er i gang med, har jeg
> forestillet mig at bruge et flerdimensionelt array til at styre
> menu-generering.
Jeg har haft stor succes med at gøre det via klasser i stedet for arrays.
f.eks. med en klasse MenuNode. Den har en parent() funktion, der returnerer en MenuNode til det overliggende punkt eller null, hvis der ikke er en overliggende.
Derudover har den en children() funktion, der returnerer et array af MenuNodes. Det kan selvfølgelig være et tomt array hvis der ikke er nogen children. Da jeg ikke ved, hvordan du gemmer dine menuer, er det svært at sige, hvodan disse funktioner skal skrives.

Nu kan din BreadCrumb laves som:
$currentNode = ... den node, du har lavet ud fra at du ved, det f.eks. er FilmOversigt, der er valgt.
//add current node
$breadCrumb = array('<a href="' . $currentNode->link() . '">' . $currentNode->text() . '</a>');
//then add parent nodes
$node = $currentNode;
while(($node = $node->parent()) {
	array_unshift($breadCrumb, '<a href="' . $node->link() . '">' . $node->text() . '</a>');
}
//then add children
$children = $currentNode->children();
foreach ($children as $node) {
	array_push($breadCrumb, '<a href="' . $node->link() . '">' . $node->text() . '</a>');
}

$breadCrumb = implode(' | ', $breadCrumb);
[klip]

Mange hilsner

Lars


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2010-07-01, 02:01 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *