TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-14-2008, 10:47 PM   #1 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default Breadcrumb Navigation?

Yeah... It just doesn't feel like this is the right way.

I serialize an array of the home/category/.../page breadcrumbness, and then I do this... It just doesn't seem like the right method. Any help?
PHP Code:
// Develop the breadcrumb Navigation
  
public function getLocation($location) {
  
  
//Unserialize the location array.
  
$location unserialize($location);
  
$return ' ';
  foreach (
$location as $url => $title) {
    if (
$url != 'current') {
      if (
$url == ROOT) {
          
$title '<img src="'.ROOT.'resources/images/house_go.gif" alt="Go to the home page" />';
      }
      
$return .= '<a href="' $url '">' $title '</a> » ';
    }
    else {
      
// Caps insensitive
      
if (strtolower($title) == 'home'){
          return 
'<img src="'.ROOT.'resources/images/house.gif" alt="You are at the home page" />';
      }
      
$return .= $title;
    }
  }
  return 
$return
  } 
__________________
Signatures are nothing but incriminating.
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 06-15-2008, 04:20 PM   #2 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by Aaron View Post
Yeah... It just doesn't feel like this is the right way.

I serialize an array of the home/category/.../page breadcrumbness, and then I do this... It just doesn't seem like the right method. Any help?
PHP Code:
// Develop the breadcrumb Navigation
  
public function getLocation($location) {
  
  
//Unserialize the location array.
  
$location unserialize($location);
  
$return ' ';
  foreach (
$location as $url => $title) {
    if (
$url != 'current') {
      if (
$url == ROOT) {
          
$title '<img src="'.ROOT.'resources/images/house_go.gif" alt="Go to the home page" />';
      }
      
$return .= '<a href="' $url '">' $title '</a> » ';
    }
    else {
      
// Caps insensitive
      
if (strtolower($title) == 'home'){
          return 
'<img src="'.ROOT.'resources/images/house.gif" alt="You are at the home page" />';
      }
      
$return .= $title;
    }
  }
  return 
$return
  } 
First off, you haven't declared $location as an array yet, it doesn't even try to validate it as an array, which could be something wrong, plus unserialize only works on strings.

Now, breadcrumbs are just links on a navbar correct?
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 06-15-2008, 08:18 PM   #3 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default

I was actually hoping for some totally different method >.< breadcrumb navigation is at the top of this page.

" TalkPHP > Developer Forums > General » Breadcrumb Navigation?"
__________________
Signatures are nothing but incriminating.
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 06-18-2008, 12:39 AM   #4 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

I forgot what a breadcrumb was, thanks.

But your breadcrumb isn't in the sql, so what are you doing?
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 06-18-2008, 01:42 AM   #5 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

There's a lot of different ways you could go about it. I think he's referring to a method of using the URI to build a breadcrumb, not one based on any database. Off the top of my head,

PHP Code:
function crumby ($szCurPage$szSeperator='&raquo;'$szRoot=NULL) {
    
    
$aPath explode('/'$_SERVER['REQUEST_URI']);

    
$szTrail = (isset($szRoot)) ? 'http://'.$szRoot.'/' 'http://'.$_SERVER['HTTP_HOST'].'/';

    
$szReturn ' <a href="'.$szTrail.'">Home</a> '.$szSeperator;        

    
$intLoop count($aPath)-1;

    for(
$i=1$i $intLoop$i++) {

        
$szTitle ucwords(str_replace('_'' '$aPath[$i]));
        
$szTrail .= $aPath[$i].'/';

        
$szReturn .= ' <a href="'.$szTrail.'">'.$szTitle.'</a> '.$szSeperator;
    }

    
$szReturn .= ' <strong>'.$szCurPage.'</strong>';

    return 
$szReturn;
}

echo 
crumby('You Are Here!'); 
This method wouldn't work well with unreadable URI's, but it's a start.
-m
delayedinsanity is offline  
Reply With Quote
Old 06-21-2008, 04:07 AM   #6 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default

Actually, it is from a database that I need to pull the information.

The name of the crumb will be the title column of the page, the problem is dynamic URLs and actually figuring out what pages are above the current one.

Also, delayed, why do you say URI? I wouldn't use a URN, and I doubt 99% of the web development community would use one, so why confuse non-web-savvy people like me by saying URI? :(
__________________
Signatures are nothing but incriminating.
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 06-21-2008, 04:39 AM   #7 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

I use them pretty interchangeably, considering a URL is a URI. Just one of those pesky habits.
-m
delayedinsanity is offline  
Reply With Quote
Old 06-22-2008, 02:55 PM   #8 (permalink)
The Acquainted
 
drewbee's Avatar
 
Join Date: May 2008
Posts: 175
Thanks: 9
drewbee is on a distinguished road
Default

Please see the following article:
Storing Hierarchical Data in a Database [PHP & MySQL Tutorials]

I am not sure how you have your database setup, but my guess is you allow subcategories upon subcategories correct? And you link them by 'parent_id', which can cause a huge amount of queries.

The tutorial above can show you how to setup categories properly, above all, get all children of x category and its breadcrumbs with a grand total of 3 queries.

This method you dont have to have the sql 'follow' the tree and have to re-query each time it gets a child deeper.

They even have a function on the tutorial somewhere that will convert your parent_id linkage to the correct method.

Good luck!!
Send a message via AIM to drewbee
drewbee is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 01:13 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design