RE: [PEAR] re: Tree navigation via links
| From: | Joseph Blythe | Date: | Tue, 29 Apr 2003 08:04:43 +0000 |
| Subject: | RE: [PEAR] re: Tree navigation via links | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-5110@lists.php.net to get a copy of this message | ||
Hi Wolfram,
Thankyou for you feedback, just what I needed to get my brain into gear :)
I had a good look at the mentioned tutorial on the excellant phpkitchen
website, and tried to get a working example running but soon ran into
problems, I dont think I not passing the options correctly or something ? I
have tried to trace this through the classes but soon lost the plot :)
I have tried passing options quite a number of ways also using the
'columnNameMaps' index containg an array but still get undefined index error
messages from Common.php
The _myTree database table looks like so:
id int(11) unsigned NOT NULL auto_increment,
name varchar(50) NOT NULL default '',
l int(11) unsigned NOT NULL default '0',
r int(11) unsigned NOT NULL default '0',
parent int(11) unsigned NOT NULL default '0',
comment varchar(255) NOT NULL default '',
user_id int(11) NOT NULL default '0',
PRIMARY KEY (id)
I have tried to keep it really simple so I can work out whats happening have
a look at:
http://demo.optcom.net.au/categories.php
The root of the above site is the catalogue demo I am working on very
unfinished :) products.php would list all of the root nodes on left menu
then when one is clicked display the children in center of page, when one of
these is clicked it would just keep going through categories until it hit a
product, then display the actual product.
I have allows viewing of source as I have nothing worth hiding :)
Hope this helps explain things better think am very close.
Regards,
Joseph
-----Original Message-----
From: Wolfram Kriesing [mailto:wolfram@visionp.de]
Sent: Monday, 28 April 2003 6:14 PM
To: Joseph Blythe
Cc: Pear-General (E-mail)
Subject: Re: [PEAR] re: Tree navigation via links
Hi Joseph,
I think you need to use the Dynamic_DB* interface for your tree, this
way you can read out the data you really need.
Please see
http://www.phpkitchen.com/article.php?story=20030427152620585
for a introductory tutorial
Your problem, you might attack it like this:
$root = $tree->getRoot();
$rootId = $root['id'];
// get the first level, that means all the children of the root
$firstLevel = $tree->getChildren($rootId);
// get the entire path to your current element
// where the $_REQUEST['id'] is simply the element the user had
// clicked on
$path = $tree->getPath($_REQUEST['id']);
// and to show the user the children of the current item
// you might want to do this
$children = $tree->getChildren($_REQUEST['id']);
now you only have to render the data :-)
properly
therefore you might want to build an array like this which you simply
have to loop through later ...
// the very first item is always the root, i guess
// if you dont need the root, simply leave out this line
$items = array($root);
foreach ($firstLevel as $aNode) {
$items[] = $aNode;
// add the $path at the appropriate place
if ($aNode['id'] == $path[1]['id']) {
array_shift($path); // remove the root
array_shift($path); // remove the node which is equal $aNode
array_merge($items,$path); // add all the other items
}
}
i havent tried the code, but i hope i could transport the idea.
i know it should be easier. if any of you has an idea how to make it
easier, may be adding a method in Tree, which does that ... your input
is welcome
regards
Wolfram
Joseph Blythe wrote:
> Hey all,
>
> I was wondering how one would go about navigating a PEAR Tree structure by
> using links, what I would like to be able to do is list all the top level
> nodes as links and as the user clicks through each one it would pass it's
id
> and list all of its children (using the same page). I do not want to
display
> the whole tree at one time, only the top level nodes then each child.
>
> The reason I am thinking of this is I have a bunch of product categories
in
> a DB and need a easy way to allow a user to navigate them, because the
> categories are content managed and infinite I have to have to find a way
to
> navigate them to the product level easily no matter how many categories it
> takes to reach them.
>
> I have a working Tree_Menu, using the same data but this is far from what
I
> want on the display/navigation side, I hope this makes some sense if
anyone
> has any suggestions/examples or just want to tell me how stupid I am then
> feel free )
>
> I guess I was thinking of maybe trying to extend Tree_Menu to allow this
> kind of navigation but I must admit is probally beyond me at the moment.
>
> Any help appreciated,
>
> Regards,
>
> Joseph Blythe
>
>
>
>
>
--
Wolfram
... opensource @ vision:produktion ...
http://opensource.visionp.de
... translating template engine ....
http://sf.net/projects/simpletpl
... authentication system ....
http://sf.net/projects/auth
--
PEAR General Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php