Skip to content

Instantly share code, notes, and snippets.

@jp-resource
Last active November 16, 2018 03:23
Show Gist options
  • Save jp-resource/f63a587454be8a2c112ef5649fe51e87 to your computer and use it in GitHub Desktop.
Save jp-resource/f63a587454be8a2c112ef5649fe51e87 to your computer and use it in GitHub Desktop.
class Breadcumbs
{
protected items = [];
public function add($label, $url = null, $extras = null)
{
if(is_array($label)) {
foreach($label as $key => $url) {
$this->items[] = $this->item_object($key, $url, $extras)
}
} else {
$this->items[] = $this->item_object($label, $url, $extras)
}
}
private function item_extras($label, $url, $extras)
{
$obj = new stdClass;
$obj->label = $label;
$obj->url = $url;
$obj->extras = $extras;
return $obj;
}
public function view($view, $extras = null)
{
return load_theme_partial($view, [
'items' => $this->items,
'extras' => $extras,
]);
}
}
//usage
$this->breadcrumbs->add([
'brands' => $url,
$brand->get_name() => current_url(),
]);
echo $this->breadcrumbs->view('_breadcrumbs');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment