How to create Bread crumb using Php Codeigniter

http://jumnuoy.blogspot.com/2013/12/how-to-create-bread-crumb-using-php.html

1-Create breadcrumbs.php

Below Php code used to create the Breadcrumb URLs. Put breadcrumbs.php file under


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

  class Breadcrumbs {

  private $breadcrumbs = array();

  private $separator = '  >  ';

  private $start = '<div id="breadcrumb">';

  private $end = '</div>';


public function __construct($params = array()){

  if (count($params) > 0){

  $this->initialize($params);

  } 

  }

  

  private function initialize($params = array()){

  if (count($params) > 0){

  foreach ($params as $key => $val){

  if (isset($this->{'_' . $key})){

  $this->{'_' . $key} = $val;

  }

  }

  }

  }


function add($title, $href){ 

  if (!$title OR !$href) return;

  $this->breadcrumbs[] = array('title' => $title, 'href' => $href);

  }

  

  function output(){


if ($this->breadcrumbs) {

  

  $output = $this->start;


foreach ($this->breadcrumbs as $key => $crumb) {

  if ($key){ 

  $output .= $this->separator;

  }


if (end(array_keys($this->breadcrumbs)) == $key) {

  $output .= '<span>' . $crumb['title'] . '</span>'; 

  } else {

  $output .= '<a href="' . $crumb['href'] . '">' . $crumb['title'] . '</a>';

  }

  }

  

  return $output . $this->end . PHP_EOL;

  }

  

  return '';

  }


}



2-Use breadcrumbs.php Controller

 Load the Breadcrumb library $this->load->library('breadcrumb'); folder. append_crumb method is used to append the bread crumb items.

    function __construct() {
        parent::__construct();
        $this->load->library('breadcrumbs');
    }

// business method
public function index(){  
        /* Bread crum */
        $this->breadcrumbs->add('Home', base_url());
        $this->breadcrumbs->add('User', base_url().'user/index');  
        $this->breadcrumbs->add('Register', base_url().'user/register');
        $data['breadcrumb'] = $this->breadcrumbs->output();   
}

3-Use in View
<?php echo (!empty($breadcrumb)?$breadcrumb:'');?>


1-Create breadcrumbs.php

Below Php code used to create the Breadcrumb URLs. Put breadcrumbs.php file under


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

  class Breadcrumbs {

  private $breadcrumbs = array();

  private $separator = '  >  ';

  private $start = '<div id="breadcrumb">';

  private $end = '</div>';


public function __construct($params = array()){

  if (count($params) > 0){

  $this->initialize($params);

  } 

  }

  

  private function initialize($params = array()){

  if (count($params) > 0){

  foreach ($params as $key => $val){

  if (isset($this->{'_' . $key})){

  $this->{'_' . $key} = $val;

  }

  }

  }

  }


function add($title, $href){ 

  if (!$title OR !$href) return;

  $this->breadcrumbs[] = array('title' => $title, 'href' => $href);

  }

  

  function output(){


if ($this->breadcrumbs) {

  

  $output = $this->start;


foreach ($this->breadcrumbs as $key => $crumb) {

  if ($key){ 

  $output .= $this->separator;

  }


if (end(array_keys($this->breadcrumbs)) == $key) {

  $output .= '<span>' . $crumb['title'] . '</span>'; 

  } else {

  $output .= '<a href="' . $crumb['href'] . '">' . $crumb['title'] . '</a>';

  }

  }

  

  return $output . $this->end . PHP_EOL;

  }

  

  return '';

  }


}



2-Use breadcrumbs.php Controller

 Load the Breadcrumb library $this->load->library('breadcrumb'); folder. append_crumb method is used to append the bread crumb items.

    function __construct() {
        parent::__construct();
        $this->load->library('breadcrumbs');
    }

// business method
public function index(){  
        /* Bread crum */
        $this->breadcrumbs->add('Home', base_url());
        $this->breadcrumbs->add('User', base_url().'user/index');  
        $this->breadcrumbs->add('Register', base_url().'user/register');
        $data['breadcrumb'] = $this->breadcrumbs->output();   
}

3-Use in View
<?php echo (!empty($breadcrumb)?$breadcrumb:'');?>

2 comments:

Anonymous said...

how can I send it to view. I got this error Severity: Notice
Message: Array to string conversion....Any help would be highly appreciated!!!!

Anonymous said...

Any one know how to clear this message..Message: Only variables should be passed by reference
Filename: libraries/breadcrumbs.php
Line Number: 74
Thanks and highly appreciate for any help

Post a Comment

Followers

រឿង ដែលខានមើលមិនបាន

Contact us

Name

Email *

Message *

Your Language

Online

Copyright 2009 Simplex Celebs All rights reserved Designed by www.sruol9.com