Using Breadcrumbs with cakePHP

Generating neat looking breadcrumbs (or breadcrumb trails) with cakePHP is almost too easy to write an extra article for it… but I’ll do it anyway. There are actually only two things that have to be done: Add the following line of code where you want your breadcrumbs to appear (that is the exact place in your design template):
<?php echo $html->getCrumbs(' > ','Home'); ?>
The first parameter of getCrumbs is the placeholder between two trail entries, which can be freely chosen. You can also replace “Home” with anything you like - this is going to be the first element of your breadcrumbs. And then second, add the specific bread crumbs to each view using this type of code:
<?php $html->addCrumb('Something', '/controller'); ?>
<?php $html->addCrumb('Something else', '/controller/method'); ?>
That’s it! You can add as many breadcrumbs to a view as you like - you also don’t have to worry about the location where you add the addCrumb call as it doesn’t matter. It just has to be somewhere in your view file. The navigation entries don’t have to belong to the same controller, so you can even combine different controllers and methods. There is only really one thing to notice: on your homepage where you usually only have the getCrumbs method called and no addCrumb call, there will be no breadcrumb trail shown! So don’t expect just a single “Home” or something to appear on the mainpage. Only “Home > First Entry” will be shown with additional crumbs added to your trail. If you want to have “Home” on your mainpage you can add an empty breadcrumb which will return “Home >”. I don’t think this is particularly nice, but have no better solution to offer at the moment. If you know a more elegant way of just displaying “Home” please let us know by commenting this entry!