Welcome Guest, Not a member yet? Register   Sign In
Solved: How to Dynamic breadcrumbs based on uri segment??
#1

[eluser]CtheB[/eluser]
Hi,

Does somebody know somethin' like a helper for dynamic breadcrumbs based on uri?
Somethin' like this:
(But then smarter and less code. So you can have unlimited breadcrumbs.)
Code:
<?php
        echo anchor(base_url(), $this->system->site_name);
        for ($i = 1; $i <= 5; $i++)
        {
            if($this->uri->segment($i) != '' )
            {
                if($this->uri->segment(2) != '' && $i == 2)
                {
                    $this->seg1= $this->uri->segment(1).'/';
                }
                else
                {
                    $this->seg1= '';
                }
                if($this->uri->segment(3) != '' && $i == 3)
                {
                    $this->seg1= $this->uri->segment(1).'/';
                    $this->seg2= $this->uri->segment(2).'/';
                }
                else
                {
                    $this->seg2= '';
                }
                if($this->uri->segment(4) != '' && $i == 4)
                {
                    $this->seg1= $this->uri->segment(1).'/';
                    $this->seg2= $this->uri->segment(2).'/';
                    $this->seg3= $this->uri->segment(3).'/';
                }
                else
                {
                    $this->seg3= '';
                }
            if($this->uri->segment(5) != '' && $i == 5)
                {
                    $this->seg1= $this->uri->segment(1).'/';
                    $this->seg2= $this->uri->segment(2).'/';
                    $this->seg3= $this->uri->segment(3).'/';
                    $this->seg4= $this->uri->segment(4).'/';
                }
                else
                {
                    $this->seg4= '';
                }
                echo '  >>  ';
                echo anchor(base_url().$this->seg1.$this->seg2.$this->seg3.$this->seg4.$this->uri->segment($i), $this->uri->segment($i));
            }
        }
?&gt;

I tried to rewrite it with more for loops in it. but i can't figure it out yet:

Code:
&lt;?php

echo anchor(base_url(), $this->system->site_name);
        for ($i = 1; $i <= 5; $i++)
        {
            if($this->uri->segment($i) != '' )
            {
                for ($j = 1; $j <= 5; $j++)
                {
                    for($k = 1; $k == $j; $k++)
                    {
                        if($this->uri->segment($j+1) != '' && $i == $j+1)
                        {
                            $seg[$k] = $this->uri->segment($k).'/';
                        }
                        else
                        {
                            $seg[$k] = '';
                        }
                    }
                }
                foreach($seg as $se)
                {
                    $this->theseg .= $se;
                }
                echo '  >>  ';
                echo anchor(base_url().$this->theseg.$this->uri->segment($i), $this->uri->segment($i));
            }
        }
?&gt;
(echoes only first and last uri segment, not the uri segments in between...)

Thnx for helping me out!

Greetz Carlos


Messages In This Thread
Solved: How to Dynamic breadcrumbs based on uri segment?? - by El Forum - 01-13-2009, 09:29 AM



Theme © iAndrew 2016 - Forum software by © MyBB