On Sun, 21 Oct 2001 01:12:28 +0200
"Paul Gillingwater" <[EMAIL PROTECTED]> wrote:

> I'm sure this is reinventing the wheel, but I couldn't find any prior art, so I'll 
>post this in case it helps other Midgarders.
> 
> I am not happy with the way that a page has to be linked to a topic solely by 
>hardcoding with the topic ID.
> 
> You know the drill -- mgd_get_topic(17) -- you first have to know what ID the topic 
>has that you're interested in.  So I got to thinking -- why not create a topic tree
> that matches the names of your page tree, and use the page name to look for a match 
>with the topic names?  Anyway, I soon ran into a problem, but found an ugly
> workaround, so I'm posting the code for feedback.
> 
> Specifically, I've got it working to two levels of depth.  My problem is that the 
>mgd_get_topic_by_name requires the ID of the "up" record, i.e., the parent topic.
> So, when looking at the top level, this will be zero, but below that, you need to 
>know where you are in the topic tree.  The only solution I could think of was to
> parse the URI, and look at the basename of the dirname, then assume that's top 
>level.  Can anyone tell me a more elegant way to find the place you are in a topic 
>tree
> based on the URI (other than recursively parsing upwards) or perhaps a mechanism for 
>searching for topics by name without having to know the parent topic?
> 
> Here's my code:

<snip>

To be able to go deeper than 2 levels, instead of dirname() and basename(), you may 
use explode("/", $midgard->uri)

Example:
<?
$path = explode("/", $midgard->uri);
for($i = $up = 0; $i < count($path); $i++) {
  if(!$path[$i]) continue; // eliminate the first slash and double-slashes
  $topic = mgd_get_topic_by_name($up, $path[$i]);
  $up = $topic->id;
}
var_dump($topic);
?>

Hope that helps.

David

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to