Skip to content

Instantly share code, notes, and snippets.

@estadoactivo
Created November 11, 2013 10:10
Show Gist options
  • Save estadoactivo/7410906 to your computer and use it in GitHub Desktop.
Save estadoactivo/7410906 to your computer and use it in GitHub Desktop.
Breadcrumb
class TBreadcrumb {
private $breadcrumb = array();
private $str_link = '<a href="$1">$2</a>';
public function Set($key,$value) {
$this->$key = $value;
}
public function Push($key,$value) {
$i = count($this->breadcrumb);
$this->breadcrumb[$i]['title'] = $key;
$this->breadcrumb[$i]['link'] = $value;
}
public function Make($bracket=' » ') {
$total = count($this->breadcrumb);
$output = '';
for ($i=0;$i<$total-1;$i++) {
$swap = str_replace('$1',$this->breadcrumb[$i]['link'],$this->str_link);
$swap = str_replace('$2',$this->breadcrumb[$i]['title'],$swap);
if ($i>0) $output .= $bracket . $swap; else $output .= $swap;
}
$swap = $this->breadcrumb[$i]['title'];
if ($i>0) $output .= $bracket . $swap; else $output .= $swap;
return $output;
}
}
//Usage
/*
$Breadcrumb = new TBreadcrumb();
$Breadcrumb->Push('Inicio','http://midominio.com');
$Breadcrumb->Push('Listado de articulos','http://midominio.com/articulos');
$Breadcrumb->Push('Televisores','http://midominio.com/articulos/teles');
echo $Breadcrumb->Make();
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment