Welcome Guest, Not a member yet? Register   Sign In
SimpleWay breadCrumbs
#1

[eluser]Yakow[/eluser]
Hey dudes, I made a simple way to do a Breadcrumbs. For my case this function are ok.

The Helper:

Code:
<?php

    if (!defined('BASEPATH'))
        exit('No direct script access allowed');

    /*
      Document   : breadcrumbs_helper
      Created on : Apr 24, 2013, 9:45:24 AM
      Author     : mario
      Description: metodo criado para gerar breadcrumbs
     */
    
    function adicionar_caminho($way){
        /*
         * Recebe o caminho do controller, dá um exeplode para trasnformar em
         * array.
         */
        $crumb = explode('/',$way);
        
        /*
         * coloca as primeiras letras de cada palavra em maiusculo e gera um
         * link.
         */
        foreach ($crumb as $c):
            // pega o tamanho do array.
            $result = count($crumb);
            /*
             * se o array for menor ou igual a 1, entende que ele está no
             * controller raiz, e será linkado para o mesmo.
             */
            if($result<=1){
                $url_crumb[] = '<a href="">'.ucfirst($c).'</a>';
            }else{
                $url_crumb[] = '<a href="'.$c.'">'.ucfirst($c).'</a>';
            }
        endforeach;
        // da um implode adicionando '>' entre as palavras.
        $fim = implode(' > ',$url_crumb);
        
        return 'Are you in: '.$fim;
        
    }
?&gt;

How to you call this helper in your controller:

Code:
$data['bread'] = adicionar_caminho($this->uri->uri_string());

Simple way Smile Sorry for my bad english and ty guys.
#2

[eluser]umefarooq[/eluser]
you can improve it with the following code

Code:
&lt;?php

    if (!defined('BASEPATH'))
        exit('No direct script access allowed');

    /*
      Document   : breadcrumbs_helper
      Created on : Apr 24, 2013, 9:45:24 AM
      Author     : mario
      Description: metodo criado para gerar breadcrumbs
     */
    
    function simpleway($ignore_segment=array(),$list=FALSE,$attrs = array()){
        /*
         * Recebe o caminho do controller, dá um exeplode para trasnformar em
         * array.
         */

        $ignore_segment = (!is_array($ignore_segment))?array($ignore_segment):$ignore_segment;

        $ci = &get;_instance();

         $crumb = $ci->uri->segment_array();
        
         $result = $ci->uri->total_segments();

        
        /*
         * coloca as primeiras letras de cada palavra em maiusculo e gera um
         * link.
         */

        $url_crumb = array();

        foreach ($crumb as $key =>$c):
            // pega o tamanho do array.

            /*
             * se o array for menor ou igual a 1, entende que ele está no
             * controller raiz, e será linkado para o mesmo.
             */

            if(!in_array($key, $ignore_segment)){

                if($result<=1){
                    $url_crumb[] = anchor('',ucfirst($c));//'<a href="">'.ucfirst($c).'</a>';
                }else{
                    $url_crumb[] = anchor($c,ucfirst(str_replace(array('_','-'), ' ', $c)));
                }
                
            }
      
            
        endforeach;
        // da um implode adicionando '>' entre as palavras.

        $fim = implode(' > ',$url_crumb);

         if($list)
         $fim =  ul($url_crumb,$attrs);
        
        if(!empty($fim))

        return 'Are you in: '.$fim;
        
    }
?&gt;

now you can call helper with following ways

Code:
echo simpleway(); // default out put
echo simpleway(1); // this will ignore first segment of url
echo simpleway(array(1,4)) // this will ignore first and 4th segment for crumb
echo simpleway(1,TRUE); // this will create unorder html list
echo simpleway(1,TRUE,array('class'=>'test')); // can define attributes for ul list
echo simpleway(null,TRUE,array('class'=>'test')); // this will print all segment of url in crumb
#3

[eluser]Yakow[/eluser]
Nice ! Smile
#4

[eluser]Yakow[/eluser]
Edited.
#5

[eluser]quickshiftin[/eluser]
Very nice contribution!




Theme © iAndrew 2016 - Forum software by © MyBB