i have this class

<?php
ob_start();
session_start();
include 'db_con.php';
/**
 *
 * @Create Breadcrumbs Trail.
 *
 * @copyright Copyright (C) 2008 PHPRO.ORG. All rights reserved.
 *
 * @version //autogentag//
 *
 * @license new bsd http://www.opensource.org/licenses/bsd-license.php
 *
 * @filesource
 *
 * @package Breadcrumbs
 *
 * @Author Kevin Waterson
 *
 */

class breadcrumbs{

    /*
     * @string $breadcrumbs
     */
    public $breadcrumbs;

    /*
     * @string $pointer
     */
    private $pointer = '&raquo;';

    /*
     * @string $url
     */
    private $url;

    /*
     * @array $parts
     */
    private $parts;


    /*
     * @constructor - duh
     *
     * @access public
     *
     */
    public function __construct()
    {
        $this->setParts();
        $this->setURL();
        $this->breadcrumbs = '<a class="bc" href="'.$this->url.'"><img src="http://'.$_SERVER['HTTP_HOST'].'/images/home.png" style="vertical-align:middle;" /></a>';
    }


    /*
     *
     * @set the base url
     *
     * @access private
     *
     */
    private function setURL()
    {
        $protocol = $_SERVER["SERVER_PROTOCOL"]=='HTTP/1.1' ? 'http' : 'https';
        $this->url = $protocol.'://'.$_SERVER['HTTP_HOST'];
    }


    /*
     * @set the pointer 
     *
     * @access public
     *
     * @param string $pointer
     * 
     */
    public function setPointer($pointer)
    {
        $this->pointer = $pointer;
    }


    /**
     *
     * @set the path array
     *
     * @access private
     *
     * @return array
     *
     */
    private function setParts()
    {
        $parts = explode('/', $_SERVER['REQUEST_URI']);
        array_pop($parts);
        array_shift($parts);
    $this->parts = $parts;
    }


    /**
     *
     * @create the breadcrumbs
     *
     * @access public
     *
      */
    public function crumbs()
    {
        foreach($this->parts as $part)
        {
            if  ($part=='login') {
                $this->url .= "/$part";
                $repl = array('_', '...');
                $this->breadcrumbs .= " $this->pointer ".'<a class="bc" href="'.$this->url.'">'.strtoupper(str_replace($repl, ' ', $part)).'</a>'; 
            } else if ($part=='contact') {
                $this->url .= "/$part";
                $repl = array('_', '...');
                $this->breadcrumbs .= " $this->pointer ".'<a class="bc" href="'.$this->url.'">'.strtoupper(str_replace($repl, ' ', $part)).'</a>';
            } else if ($part=='registration') { 
                $this->url .= "/$part";
                $repl = array('_', '...');
                $this->breadcrumbs .= " $this->pointer ".'<a class="bc" href="'.$this->url.'">INREGISTARE</a>';
            } else if ($part!='jocuri') {
                $this->url .= "/jocuri/$part";
                $repl = array('_', '...');
                $this->breadcrumbs .= " $this->pointer ".'<a class="bc" href="'.$this->url.'">'.strtoupper(str_replace($repl, ' ', $part)).'</a>';    
            } else if ($part!='user') {
                $this->url .= "/$part";
                $repl = array('_', '...');
                $this->breadcrumbs .= " $this->pointer ".'<a class="bc" href="'.$this->url.'">'.strtoupper(str_replace($repl, ' ', $part)).'</a>';
            }
        }
    }
} /*** end of class ***/

?>

and this that is two levels deep, i included the above class of course, to display

<?php
/*** a new breadcrumbs object ***/
$bc = new breadcrumbs;

/*** set the pointer if you like ***/
$bc->setPointer('<img src="../../images/bullet_arrows.png" style="vertical-align:middle;"/>');

/*** create the trail ***/
$bc->crumbs();

/*** output ***/
echo $bc->breadcrumbs;

the last code should remove the "USER" link from breadcrumbs, this code:

else if ($part!='user') {
                $this->url .= "/$part";
                $repl = array('_', '...');
                $this->breadcrumbs .= " $this->pointer ".'<a class="bc" href="'.$this->url.'">'.strtoupper(str_replace($repl, ' ', $part)).'</a>';
            }

but it doesn't work why?

Recommended Answers

All 12 Replies

    else if ($part!='user') {
        $this->url .= "/$part";
        $repl = array('_', '...');
        $this->breadcrumbs .= " $this->pointer ".'<a class="bc" href="'.$this->url.'">'.strtoupper(str_replace($repl, ' ', $part)).'</a>';
    }

This appears to skip any $part that is named "user", correct? It seems that there is not another else { } part in your script, so from what I'd expect, the "user" parts should be skipped.

What exactly is happening?

for 'jocuri' it worked has removed the "JOCURI" link from breadcrumbs, the links output was "HOME>JOCURI>ACTIUNE>JOCURI" and after doing the change the link output is "HOME>ACTIUNE" exactly what i want, but for 'user' doesn't work, it still displays the "HOME>USER>NAME_OF_USER" and the link at "NAME_OF_THE_USER" is like "localhost://user/jocuri/name_of_user" somehow it took the case from

else if ($part!='jocuri') {
$this->url .= "/jocuri/$part";
$repl = array('_', '...');
$this->breadcrumbs .= " $this->pointer ".'<a class="bc" href="'.$this->url.'">'.strtoupper(str_replace($repl, ' ', $part)).'</a>'; 

i also tried

trim($this->url, 'jocuri')

still no result

Hm this sounds like you would have to add an exception for each and every username that is being used in your system, am I right? For example you'd have to add an elseif($part == 'minitauros') {} if I were a user, right? This sounds a bit too complex, if you ask me.

If this is indeed the case, you would probably be better off by checking if the current collection of breadcrumbs is pointing to any user rather than to one user in specific, and to not add any new breadcrumbs if the breadcrumbs are pointing to a user.

Am I on the right track here? :)

no i need it to delete the point to any user and let the pointing to a specific user but i solve it thanks a lot

Care to share how you solved it? :)

added this in the foreach

            if ($part=='user') {

            } else if ($part==$_SESSION['Username']) {
                $this->url .= "/user/$part";
                $repl = array('_', '...');
                $this->breadcrumbs .= " $this->pointer ".'<a class="bc" href="'.$this->url.'">'.strtoupper(str_replace($repl, ' ', $part)).'</a>';
            }

i encountered another problem, so i have updated the code like this:

public function crumbs()
    {
        foreach($this->parts as $part)
        {
            if ($part=='user') {

            }
            else if ($part!='jocuri') {
                $this->url .= "/jocuri/$part";
                $repl = array('_', '...');
                $this->breadcrumbs .= " $this->pointer ".'<a class="bc" href="'.$this->url.'">'.strtoupper(str_replace($repl, ' ', $part)).'</a>';    
            }
             else if ($part==$_SESSION['Username']) {
                $this->url .= "/user/$part";
                $repl = array('_', '...');
                $this->breadcrumbs .= " $this->pointer ".'<a class="bc" href="'.$this->url.'">'.strtoupper(str_replace($repl, ' ', $part)).'</a>';
            }
            else if ($part!==$_SESSION['Username']) {
                $this->url .= "/user/$part";
                $repl = array('_', '...');
                $this->breadcrumbs .= " $this->pointer ".'<a class="bc" href="'.$this->url.'">'.strtoupper(str_replace($repl, ' ', $part)).'</a>';
            }
             else if ($part=='login') {
                $this->url .= "/$part";
                $repl = array('_', '...');
                $this->breadcrumbs .= " $this->pointer ".'<a class="bc" href="'.$this->url.'">'.strtoupper(str_replace($repl, ' ', $part)).'</a>'; 
            } else if ($part=='contact') {
                $this->url .= "/$part";
                $repl = array('_', '...');
                $this->breadcrumbs .= " $this->pointer ".'<a class="bc" href="'.$this->url.'">'.strtoupper(str_replace($repl, ' ', $part)).'</a>';
            } else if ($part=='registration') { 
                $this->url .= "/$part";
                $repl = array('_', '...');
                $this->breadcrumbs .= " $this->pointer ".'<a class="bc" href="'.$this->url.'">INREGISTARE</a>';
            }
        }
    }

Which of your if() statements is triggered and why?

this script some how takes the structure of directories and puts it into links
the structure is like 'http://localhost/jocuri/action/jocuri/name_of_the_game/'
my goal is to remove somehow the 'jocuri' link from display
if statement that is triggered is the one from line 8, when i'am in 'localhost//jocuri/action/jocuri/' the link is different and is 'localhost//user/jocuri/user/action' somehow user is added. why?

Well I guess you could try and find out what is happening and why, right? :) I mean if the if() on line 8 is being triggered, that means that $part is not "jocuri" there. So what is it then and should it get added? Are you sure you are using the right setup? Because this line:

if($part==$_SESSION['Username']) {

comes after this line:

else if ($part!='jocuri') {

But what happens if $_SESSION['username'] is not 'jocuri'? It would still trigger the if() statement on line 8 instead of the next.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.