Bread Crumb Trails

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
montecristo
Forum Newbie
Posts: 20
Joined: Thu Oct 19, 2006 9:51 am

Bread Crumb Trails

Post by montecristo »

Hi Guys,

I am looking to add a breadcrumb trail to my site so if a person clicks on page 1 then goes to page 2 and on page 2 chooses to go to page 4, I want my trail to look like

page 1 > page 2 > page 4

Now I tried to use session variables to build up the path dynamically, but if a user refreshes the page it screws things up.

I also looked at some Javascript options, but the ones I looked at just breakup the url into bread crumb trails eg:
If I am looking at http://localhost/xampp/mypage.php
The Javascript returns
localhost > xampp > mypage.php

( I also saw some php classes that do the similar thing : http://www.baskettcase.com/classes/breadcrumb)

Now what I am thinking of doing is writing a php function, where you pass in the current page name, check to see if is in the path, if it is, don't add it, if it is isn't do, add it.


Any ideas on this would be great as it is begining to annoy me alot

Thanks
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

There isn't just some magic function or code snippet to do breadcrumbs. The solution depends on the framework you are using or how you have your pages setup. So I guess start there, how do you have all your pages setup? Are they just a bunch of random PHP pages than you can get through by a bunch of different links? Are you using some sort of MVC? etc.
montecristo
Forum Newbie
Posts: 20
Joined: Thu Oct 19, 2006 9:51 am

Post by montecristo »

Thanks for getting back to me,

Well some of the pages are categorized, for example there is a user object, you can search by id, name, phone etc
The others would be stock, eg. search by stock id, stock name etc

So you basically hop from one customer page to another using links.
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

I came across this in a book I was reading a couple of weeks ago. Basics of it are to create an associative array for each directory with a few properties including: directory name, url and parent directory.
I'm not sure the legalities of scanning the page and hosting it. If you want it, let me know and I'll send it to you.
montecristo
Forum Newbie
Posts: 20
Joined: Thu Oct 19, 2006 9:51 am

Post by montecristo »

I would really appreciate that impulse().

I will send you my email address and if you could send me the info, that would be brilliant.

As I said, in my first post, I was thinking of creating a function that would add the page to the trail if it wasn't already there and if it was, it wouldn't add it (This gets around the problem of using session variables and a user refreshing the page)

I will post it up here when I have finished it, done a bit of testing on it and it seems to work for me.

Thanks again
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

PM me your e-mail address.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

just check if the page is the last spot in the array already:

Code: Select all

if($breadcrumb[count($breadcrumb)-1]!=$this_page) $breadcrumb[]=$this_page;
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

viewtopic.php?t=37771 could be of interest.
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Post by matthijs »

Sorry to interrupt, but that's a cool piece of code you linked to feyd. I just decided that if I find the time I'm going to read all your posts.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

matthijs wrote:Sorry to interrupt, but that's a cool piece of code you linked to feyd. I just decided that if I find the time I'm going to read all your posts.
You'll have a tough time if you attempt to use the "find all posts by feyd" link in my profile. phpBB decides to kill itself after a page or so into the list. :)
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

feyd: 24.06 posts per day... on average!

In the words of the mighty Keanu Reeves: 8O whoa!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Kieran Huggins wrote:feyd: 24.06 posts per day... on average!

In the words of the mighty Keanu Reeves: 8O whoa!
It used to be around 30. :)
Post Reply