Hi EveryBody,
I Wonder If some one could suggest me if how i can achieve breadcumb navigation in php where all my web pages are included into index.php
for ex:
index.php?page=home for showing home page and
index.php?page=contact us for showing contact us page ....etc
and i want navaigation to be like this
home->tutorials->breadcumb.php
and i don't find any kind of help from the internet as my case is entirely different and it could get it done it will be helpful for many people who are looking for this kind of script
waiting for some suggestions guys......
Breadcrumb navigation in php
Page 1 of 18 Replies - 6385 Views - Last Post: 08 January 2012 - 02:16 PM
Replies To: Breadcrumb navigation in php
#2
Re: Breadcrumb navigation in php
Posted 07 January 2012 - 06:22 AM
I think you're asking about bootstrapping. Something like this should work:
<?php
$page = array("home"=>"Some_home_page.php", "contact"=>"contact_us.php", "bread"=>"breadcrumb.php");
if(isset($_GET['page']) && in_array($_GET['page'], $page)) {
include $page[$_GET['page']];
}
?>
#3
Re: Breadcrumb navigation in php
Posted 07 January 2012 - 08:10 AM
@CTphpnwb That's if he's using a MVC framework. Might be mistaken but I don't hear about it anywhere else.
Breadcrumbs depend on either the URI or the actual directory. If you're going to be using Apache's URL rewriting module then I'd suggest basing your breadcrumb navigation on the URI. To get the URI of a page this is what I used.
For a URI like /tutorials/php/oop/tut1.php you will get an array like tutorials | php | oop. You could make the your breadcrumb navigation from just that but more than likely you need something a bit more user-friendly. My suggestion is that you simply store the string you wish to be shown in either a database, XML file or JSON. It's up to you.
Breadcrumbs depend on either the URI or the actual directory. If you're going to be using Apache's URL rewriting module then I'd suggest basing your breadcrumb navigation on the URI. To get the URI of a page this is what I used.
implode(array_slice(explode('/', $_SERVER['REQUEST_URI']), 0, -1), '/') . '/'
This cuts off the file name as the end but since we don't need the entire string but simply the parts we don't need to run the implode function on it.
array_slice(explode('/', $_SERVER['REQUEST_URI']), 0, -1)
For a URI like /tutorials/php/oop/tut1.php you will get an array like tutorials | php | oop. You could make the your breadcrumb navigation from just that but more than likely you need something a bit more user-friendly. My suggestion is that you simply store the string you wish to be shown in either a database, XML file or JSON. It's up to you.
#4
Re: Breadcrumb navigation in php
Posted 07 January 2012 - 11:48 AM
Both examples are good. But the first example can be used outside of MVC; it's just an array, and all the code does is check the $_GET["page"] content, search the array for the $_GET["page"] value, and if it's found, it includes a certain page.
@codeprada : Your example is good, but sort of overcomplicates the steps needed to be taken, at least if the programmer were a beginner.
@codeprada : Your example is good, but sort of overcomplicates the steps needed to be taken, at least if the programmer were a beginner.
This post has been edited by xxxjj18: 07 January 2012 - 11:48 AM
#5
Re: Breadcrumb navigation in php
Posted 07 January 2012 - 11:06 PM
I don't think he's looking for URL design, although I think that's a plus, too...
For breadcrumb navigation you'd have to design some sort of database for the information to come from, such as this page[b] is a page of [b]this category etc, then loop through... I'd use a database but I'll throw a small array work around of what I'm talking about just to give you an idea of where I'd head with this...
You'll have to tweak it to make it your own, but I didn't really want to give you a solution (hell, I haven't even tested that code so it probably doesn't work) just wanted to give your gears a boost into a plausible solution. Good luck!
For breadcrumb navigation you'd have to design some sort of database for the information to come from, such as this page[b] is a page of [b]this category etc, then loop through... I'd use a database but I'll throw a small array work around of what I'm talking about just to give you an idea of where I'd head with this...
<?php
$page_dox = array(
'home' => array('home.php', 'Homepage', ''),
'contact' => array('contact.php', 'Contact Us', 'home');
'contact_joe' => array('contact_joe.php', 'Contact Joe!', 'contact');
);
function show_crumbs($page, $page_dox = array()) {
if($page_dox[$page][2] !== "") { //this is a sub cat to a category
//do the same function for the category to loop and get its parent categories
$parent = $page_dox[$page][2];
show_crumbs($page_dox[$parent], $page_dox);
echo $page_dox[$parent][1] . ' > ';
}
//else it has no parent, so do nothing.
}
if(isset($_GET['page'])) {
$thisPage = trim($_GET['page']);
show_crumbs($thisPage, $page_dox);
echo $page_dox[$thisPage][1];
//then do includes wherever?
}
?>
You'll have to tweak it to make it your own, but I didn't really want to give you a solution (hell, I haven't even tested that code so it probably doesn't work) just wanted to give your gears a boost into a plausible solution. Good luck!
#6
Re: Breadcrumb navigation in php
Posted 07 January 2012 - 11:16 PM
...or if I'm trying to dig into your thoughts too deeply and am wrong as to the perception the others have taken, a simple google search brought up a great article on not only how to split the URL into different variables, but the basics of MOD_REWRITE as well. Here it is.
#7
Re: Breadcrumb navigation in php
Posted 08 January 2012 - 10:39 AM
#8
Re: Breadcrumb navigation in php
Posted 08 January 2012 - 12:06 PM
There's no reason that array couldn't be read from a table in a database or even a flat file.
Flexibility is up to the developer.
Flexibility is up to the developer.
#9
Re: Breadcrumb navigation in php
Posted 08 January 2012 - 02:16 PM
@codeprada i know that my second post does, in case that's what he was looking for... but I didn't think by how he asked his question that he'd want to reconstruct his URLs. Also, wanted to throw more ideas on how he could go about it.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote







|