Jump to content


Photo

Bread Crumbs...HowTo


  • Please log in to reply
10 replies to this topic

#1 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 26 June 2006 - 06:23 PM

How does one do the breadcrumbs in php?

Do I use a session to keep track of where they are?

Kind like phpfreaks: PHP Help Forums > PHP and MySQL > PHP Help



#2 Leovenous

Leovenous
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 27 June 2006 - 12:59 AM

I've been wondering this myself, and yeah, sessions were the first thing that popped into my mind.

Maybe you could make a breadcrum variable that is the link, then add or subtract from it. I dunno.

#3 dptr1988

dptr1988
  • Members
  • PipPipPip
  • Advanced Member
  • 372 posts

Posted 27 June 2006 - 01:03 AM

The $_SERVER['PHP_SELF'] variable gives you your url location. Can't you use that to keep track of where the user is?
Need more help with your project? One of the thousands of programmers, web designers or artists at <a href="http://www.rentacode...d_6764522">Rent A Coder</a> would be happy to help.

Disclaimer: Free advice is usually worth what you paid for it. ( or at least when it's coming from me! )

#4 Leovenous

Leovenous
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 27 June 2006 - 01:06 AM

Its not so much where the user is, but where the user came from. For instance, in the breadcrumb for this forum, how does the "PHP Help" link know to be there, and for that matter, the links ahead of it?

#5 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 27 June 2006 - 01:07 AM

[a href=\"http://www.zend.com/zend/spotlight/breadcrumb28.php\" target=\"_blank\"]http://www.zend.com/zend/spotlight/breadcrumb28.php[/a]

[a href=\"http://www.baskettcase.com/classes/breadcrumb/\" target=\"_blank\"]http://www.baskettcase.com/classes/breadcrumb/[/a]

have fun
Legend has it that reading the manual never killed anyone.
My site

#6 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 27 June 2006 - 01:08 AM

breadcrumb examples i've seen use your dir structure. so like, if you store your files in the a dir structure in the same way you want the breadcrumbs to show, you can base your breadcrumb off that
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#7 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 27 June 2006 - 01:10 AM

[a href=\"http://www.sillybean.net/archives/452\" target=\"_blank\"]http://www.sillybean.net/archives/452[/a] as a follow-up to Crayon Violent's suggestion
Legend has it that reading the manual never killed anyone.
My site

#8 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 27 June 2006 - 02:45 PM

Ah thanx for the replies. I guess I'll have to do a combination of it.

directory and file ;) I'll play around and see what I can come up with with help of the examples you guys have posted.



#9 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 27 June 2006 - 03:19 PM

[!--quoteo(post=388522:date=Jun 27 2006, 07:45 AM:name=SharkBait)--][div class=\'quotetop\']QUOTE(SharkBait @ Jun 27 2006, 07:45 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Ah thanx for the replies. I guess I'll have to do a combination of it.

directory and file ;) I'll play around and see what I can come up with with help of the examples you guys have posted.
[/quote]

This is what I came up with:

(how I wish php tags were working ;))
<ul id="breadcrumbs">
<?php
// Get Directory Path and Scriptname to create BreadCrumbs
$parts = explode("/", dirname($_SERVER['PHP_SELF']));
echo "<li><a href=\"/\"Home</a> ";
foreach($parts as $key => $dir) {
  $label = ucwords($dir);
  $url = "";
  for($i = 1; $i <= $key; $i++) {
    $url .= $parts[$i]."/";
  }
  if($dir != "") {
    echo "<li>> a href=\"/{$url}\">{$label}</a></li> ";
  }
}
$script = explode(".", basename($_SERVER['PHP_SELF']));
if(script != "") {
  echo "<li>> ". ucwords($script[0])."</li>";
}
?>
</ul>

Thanx to the sillybean.net example and suggestions :) My Breadcrumbs look like:

Home > Admin > ScriptName


#10 matt_vo

matt_vo
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 14 November 2006 - 02:49 PM

Hi all,

I'm also using the Sillybean example. It's quite easy to use but I still have a question. What if I need to remove, or not display, the two first directories. For example, I would like to remove Home and Dir1 from:

Home > Dir1 > Dir2 > Dir3 > Here

Removing Home is easy, just commenting out, but how about Dir1? If I use unset ($parts[1]), it removes Dir1 from the breadcrumb but then the links are wrong.

Thanks
Matt

#11 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 14 November 2006 - 05:27 PM

it's hard to determine how to fix that without you showing your code, but if it's because of some kind of loop you are doing that is dependant on the array keys being 12345 instead of 1245 then you can use array_values() to reset the keys after you have unset one of them.  consider this example:

<?php
   // example array
   $blah = array('a','b','c','d','e');
   
   // display what the key - value initially looks like
   // will show keys 0,1,2,3,4
   foreach ($blah as $key => $val) {
      echo "$key - $val <br>";
   }		
   
   // unset the middle element
   unset ($blah[2]);

   // show what the key-val looks like now
   // shows 0,1,3,4 
   foreach ($blah as $key => $val) {
      echo "$key - $val <br>";
   }		
 
   // reset the keys 
   $blah = array_values($blah);
 
   // display results from reseting the keys
   // shows 0,1,2,3   
   foreach ($blah as $key => $val) {
      echo "$key - $val <br>";
    }		
?>

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users