Webpage Bread crumbing is common feature in web development. Breadcrumbs usually appear horizontally across the top of a web page, normally just below title bars or headers. BreadCrumb gives users a way to keep track of their locations within programs or documents. For using breadCrumb there must be a common component whether its can be effective in all pages through out the Site.
Here I show how to create and use a breadcrumb component in CakePHP.
<?php
class BreadcrumbComponent extends Object
{
var $controller;
var $components = array('Session','Acl');
function startup(&$controller)
{
$this->controller =& $controller;
}
function setBreadcrumb($url)
{
$crumbs = split('/',$url);
$link = '/';
if($crumbs[0] != 'admin')
{
$breadcrumb[] = array('home', $link);
}
foreach($crumbs AS $crumb)
{
$name = str_replace('_',' ', $crumb);
$link .= $crumb.'/';
if($name && !is_numeric($name))
{
$breadcrumb[] = array($name,$link);
}
elseif(is_numeric($name))
{
$key = count($breadcrumb)-1;
$breadcrumb[$key][1].= $name;
}
}
return $breadcrumb;
}
}
?>
Load the Component:
var $components = array( 'Breadcrumb');
Call from the controller:
function beforeRender()
{
$this->set('breadcrumb', $this->Breadcrumb->setBreadcrumb($this->params['url']['url']));
}
This need to be modified according to sitemap




