2011-09-16 37 views
0

我使用的是米克·西爾斯的PHP腳本的麪包屑奇怪的問題 - 在這裏找到: http://www.roscripts.com/PHP_breadcrumbs-118.html用PHP腳本麪包屑

我用這個腳本幾次,沒有任何問題。但有了這個網站,我遇到了最奇怪的問題......主頁 - 很好。一級頁 - 很好。但每次移到第2級頁面時,正確的level1麪包屑都會被「幫助」取代。麪包屑上的鏈接是幫助頁面的正確鏈接。即使我清除所有瀏覽器緩存並且根本不會轉到網站的「幫助」部分,也會發生這種情況。

該網站是http://www.fastexas.org。腳本在那裏,但我給了breadcrumb div顯示:none;直到我能弄明白爲止。

這個腳本似乎已出現一段時間,是否有人看到了這個問題,我想知道。

+0

你有任何我們可能能夠看到的周邊代碼嗎?調試沒有代碼的東西是相當困難的。 – Benjam

回答

0

麪包屑腳本:

<?php 
class Breadcrumb{ 
var $output; 
var $crumbs = array(); 
var $location; 
function Breadcrumb(){ 
    if ($_SESSION['breadcrumb'] != null){ 
    $this->crumbs = $_SESSION['breadcrumb'];} } 
function add($label, $url, $level){ 
    $crumb = array(); 
    $crumb['label'] = $label; 
    $crumb['url'] = $url; 
    if ($crumb['label'] != null && $crumb['url'] != null && isset($level)){    
    while(count($this->crumbs) > $level){ 
     array_pop($this->crumbs); } 
    if (!isset($this->crumbs[0]) && $level > 0){ 
$this->crumbs[0]['url'] = "/index.php"; 
     $this->crumbs[0]['label'] = "Home";} 
    $this->crumbs[$level] = $crumb;} 

    $_SESSION['breadcrumb'] = $this->crumbs; 
    $this->crumbs[$level]['url'] = null;} 
function output(){ 
    echo "<ul>"; 
    foreach ($this->crumbs as $crumb){ 
if ($crumb['url'] != null){ 
echo "<li> <a href='".$crumb['url']."' title='".$crumb['label']."'>".$crumb['label']."</a></li> ";} else { 
echo "<li class='last'>".$crumb['label']."</li> ";}} 
echo "</ul>";}} 
?> 

每個頁面的東西,如開頭:

<?php session_start(); 
$level= '1'; 
$label= 'Honors Circle'; 
$url= '/honors/'; include($_SERVER['DOCUMENT_ROOT']."/includes/Breadcrumb.php"); 
$trail = new Breadcrumb(); 
$trail->add($label, $url, $level); ?> 

<?php 
session_start(); 
$level= '2'; 
$label= 'Districts'; 
$url= '/honors/district.php'; 
include($_SERVER['DOCUMENT_ROOT']."/includes/Breadcrumb.php"); 
$trail = new Breadcrumb(); 
$trail->add($label, $url, $level); 
?> 

並打印麪包屑:

<div id="breadcrumb"><?php $trail->output(); ?></div>