For Programmers: Free Programming Magazines  


Home > Archive > PHP Pear > July 2007 > DB_NestedSet with HTML Menu - Can I use URL filename without ID?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author DB_NestedSet with HTML Menu - Can I use URL filename without ID?
Mark Reynolds

2007-07-04, 8:01 am

Hi, I am using:
DB_NestedSet 1.3.6
HTML_Menu 2.1.3

These are the files that I'm utilising:

require_once('HTML/Menu.php');
require_once('DB/NestedSet.php');
require_once('DB/NestedSet/Output.php');
require_once('DB/NestedSet/Menu.php');
require_once ('HTML/Menu/DirectTreeRenderer.php');

I've been following this and a couple of other tutorials:
http://jystewart.net/process/2005/0...o-db_nestedset/
http://trac.seagullproject.org/wiki...gation/HtmlMenu

The problem is that the majority of these tutorials seem to rely on the node
id being in the url in order to be able to use the PickNode function to
return the page's content. However I've been experimenting and have failed
to find a method whereby I can just make reference to the $node['name'] for
example and not the ID. JYStewart goes partly there, but instead of the
'option' directory name that Stewart uses I'm looking to include the root
name.

So if the $node['level'] is equal to 1 it displays the $node['name'] in the
URL.

eg. http://www.domain.com/root/

or if the $node['level'] is greater than 1 it displays the $node['name'] as
the filename plus it's root name as the 'directory'. I want to keep the url
down to this depth and not include subnodes etc.

eg. http://www.domain.com/root/leaf.htm

However I've been struggling with the detail/coding for this. So advice
would be appreciated on this.

Once the links are displayed correctly there's the important issue of
returning the $node[id'] based on the filename from the url, so that the ID
can be given to the PickNode function.

How can I carry the above out? Is it possible? Due to the lack of
documentation I've looked through the relevent pear files but unless I've
missed something there doesn't seem to be a function whereby I can input the
filename or similar?? Is there an option I can use that has already been
coded into the HTML MENU files for example, or do I have to change the code
within these files at some point?
Shazo

2007-07-11, 11:40 pm

Alyson Hannigan and Shania Twain With Wired Snatch!
http://www.videomoviesonline.com/Watch?movie=148803

Carmen Electra and Christina Aguilera XXXXing In Sauna!
http://www.videomoviesonline.com/a?q=148803

Paris Hilton and Helen Hunt , Satisfying Her Lesbian Girlfriend!
http://www.videomoviesonline.com/WatchTube?id=148803

Laetitia Casta and Helen Hunt Machine XXXX!
http://www.videomoviesonline.com/watch?q=148803

Lindsay Lohan and Ashlee Simpson Licking Pussy Of Busty Blindfold Babe!
http://www.videomoviesonline.com/Player?id=148803

extreme funny humor video funny halo video forum funny sexy video free funny video clip online funny sexy video clip
http://635-funny-video.info/really-...video-clip.html http://635-funny-video.info/funny-adult-video.html http://635-funny-video.info/funny-basketball-video.html http://635-funny-video.info/funny-video-yahoo.html http://635-funny-video.info/america...home-video.html
Mark Reynolds

2007-07-24, 8:02 am

Hi Daniel thanks for getting back to me. I've had to work on some other
things over the last few ws, but I'm now back concentrating on this
problem.

Just as I had hoped and as you had suggested, the things that I'm looking
for already seem to be implemented in the pear package, my problem now is
getting the correct coding to make use of them.

As I'm using DirectTreeRenderer I've displayed a sitemap using the data in
the database and it has displayed exactly as I would expect. I've also used
print_r($structure) to confirm that the array is displayed as it should, and
it is. However when I change the menu type from sitemap to tree I don't get
the desired results. All that happens is the 'tree' only displays level 1
depth. I was hoping to use it in my left navigation to display level 1&2 and
then 3 if the user clicks on 2 for instance (hope that's clear).

I tried to go back to basics to troubleshoot by just using HTML_Menu on its
own (and not directtreerenderer). Again the sitemap displays as expected
with the correct indentations, but 'urhere' and 'prevnext' only display an
empty table:
<table border="1"><tr></tr></table>Hopefully you may have come across this
before and can suggest something. By the way once this has been sorted out
I'm intending to then get to your idea of including the nodeID and the name
in the url.

Here's the main code of the HTML_Menu page that I just mentioned (I hope you
can help!):

/ ****************************************
******/
require_once('HTML/Menu.php');
require_once('DB/NestedSet.php');
require_once('DB/NestedSet/Output.php');
require_once('DB/NestedSet/Menu.php');
require_once 'HTML/Menu/DirectTreeRenderer.php';

$dsn = 'mysql://user:pw@localhost/site';

$table = array(
'id' => 'id',
'rootid' => 'rootid',
'l' => 'l',
'r' => 'r',
'norder' => 'norder',
'level' => 'level',
'name' => 'name',
'title' => 'title',
'maincontent' => 'maincontent',
'url' => 'url'
);

$nestedSet =& DB_NestedSet::factory('DB', $dsn, $table);

$nestedSet->setAttr(array(
'node_table' => 'tb_nodes',
'lock_table' => 'tb_locks',
));

?>
<html>
<head>
<?php

if(isset($_GET['nodeID'])){
$node_data = $nestedSet->pickNode($_GET['nodeID']);
echo "<title>$node_data->name : $node_data->title</title>";
}

?>
</head>
<body>
<?php

$data = $nestedSet->getAllNodes(true);

foreach ($data as $id => $node) {
$data[$id]['url'] = $_SERVER['PHP_SELF'].'?nodeID=' . $node['id'] .
'&nodename=' . filename_from_db_to_url($node['name']);
}

$params = array(
'structure' => $data,
'titleField' => 'name',
'urlField' => 'url');

$output =& DB_NestedSet_Output::factory($params, 'Menu');

$structure = $output->returnStructure();

$menu = & new HTML_Menu($structure, 'tree');

$currentUrl = $_SERVER['PHP_SELF'].'?nodeID=' . $_GET['nodeID'];
$menu->forceCurrentUrl($currentUrl);

$menu->show();

?>
</body>
</html>


"Daniel Khan" <datenpunk@php.net> wrote in message
news:0D.40.23636.8B982964@pb1.pair.com...
> Hi Mark,
>
> I am not sure if I got your point but I am doing my best :)
>
> Mark Reynolds schrieb:
> [..]
>
>
> Means
> if($level == 1) { this url }
> if($level == 1) { that url }
>
> So that shouldn't be a problem. You have to code this this way.
>
>
> I think what you are looking for is pickNode():
>
> http://pear.php.net/package/DB_Nest...#methodpickNode
> (there is no enduser docu - but the api doc is complete and verbose)
>
> <?php
> $searchNode = 'foo';
> $mynode = $NeSe->pickNode($searchNode, true, true, 'name');
> // if 'name' contains the nodename.
> ?>
>
> Another advice. You can create friendly urls using mod_rewrite and I
> really recommend to use the node id inside the url. As soon as you have 2
> nodes with the same name your code won't work anymore.
> Look at
> - http://www.shopping.at/Baby_kind,564/Baby_und_Kind.html
> - http://www.fisherprice.at/fisher-pr...nds-Kat762.html
>
> I've used DB_Nested in both and both have the id inside the url.
> The are still search engine friendly..
>
> (http://www.google.at/search?q=site%3Awww.shopping.at)
>
> Hth - just ask if you need more help
>
> --
> Daniel Khan

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com