TalkPHP
 
 
Account Login
Latest Articles
» How to keep your forms from double posting data
» cURL Basics
» Securing your PHP applications Part 1
» The way the function rolls
» Database Abstraction with Zend_Db - Part 2
Advertisement
Associates
Associates
techtuts Darkmindz
CSS Tutorials Tutorialsphere.com - Free Online Tutorials
Boston PHP SurfnLearn
Reply
 
LinkBack Thread Tools Display Modes
Old 06-14-2008, 10:47 PM   #1 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 368
Thanks: 44
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
  } 
__________________

I feel better hating IE.
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
Location: On your Hard Drive, hiding like a Virus
Posts: 779
Thanks: 154
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?
__________________
Wax on, Wax off
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: 368
Thanks: 44
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?"
__________________

I feel better hating IE.
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
Location: On your Hard Drive, hiding like a Virus
Posts: 779
Thanks: 154
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?
__________________
Wax on, Wax off
Orc is offline  
Reply With Quote
Old 06-18-2008, 01:42 AM   #5 (permalink)
The Gregarious
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Cana'derr
Posts: 653
Thanks: 24
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: 368
Thanks: 44
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? :(
__________________

I feel better hating IE.
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 06-21-2008, 04:39 AM   #7 (permalink)
The Gregarious
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Cana'derr
Posts: 653
Thanks: 24
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
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 10:32 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0