How to create Bread crumb using Php Codeigniter

14 Mei 20130 komentar


Breadcrumb navigation provides the simple facility to indicate the steps, or path or how user has reach to the current page of a website. Its a simple navigation approach. Now a days website depth is increased, so the website should have provision of Breadcrumb bar which shows the depth of pages.
Most of website users using the browsers "Back" button, if they don't have Breadcrumb navigaion option. Or the websites primary navigation to return to a higher level page. Step #1:- Create BreadcrumbComponent.php Below Php code used to create the Breadcrumb URLs. Put Breadcrumb.php file under "system/application/libraries" folder.
php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class BreadcrumbComponent {
 private $breadcrumbs = array();
 private $separator = '  ›  ';
 private $start = '
;
 private $end = '
'
; 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 .= '' . $crumb['title'] . ''; } else { $output .= ' . $crumb['href'] . '">' . $crumb['title'] . ''; } } return $output . $this->end . PHP_EOL; } return ''; } } Step #2:- Use Breadcrumb in Php Controller Load the Breadcrumb library $this->load->library('breadcrumb'); folder. append_crumb method is used to append the bread crumb items.
function Tutorial(){
  parent::Controller();
  $this->load->library('breadcrumbcomponent');
}

// business method
public function index(){  
  /* Bread crum */
  $this->breadcrumbcomponent->add('Home', base_url());
  $this->breadcrumbcomponent->add('Tutorials', base_url().'tutorials');  
  $this->breadcrumbcomponent->add('Spring Tutorial', base_url().'tutorials/spring-tutorials');  
  
}
Step #3:- Finish :) Enjoy the How to create breadcrumb using php codeigniter
breadcrumb using php codeigniter
Sumber : http://www.technicalkeeda.com/
Share this article :

Posting Komentar


 

Copyright © 2011. MargoNulis.blogspot.com - All Rights Reserved

Powered by Blogger