A while back I needed a breadcrumb helper for a Zend Framework project I was working on. Not wanting to reinvent the wheel, I went out searching for one on the good ol’ world wide web to no avail. So then went ahead and created one myself.
This is what I have come up with.
In your [...]
A while back I needed a breadcrumb helper for a Zend Framework project I was working on. Not wanting to reinvent the wheel, I went out searching for one on the good ol’ world wide web to no avail. So then went ahead and created one myself.
This is what I have come up with.
In your controller, you will create a multi-dimensional array of breadcrumbs in the following format:
[0]
[title] Home
[url] /
[1]
[title] Blog
[url] /blog/
[2]
[title] Edit
[url] NULL
You will then send this multi-dimensional array to the breadcrumb helper which will format the breadcrumbs and return the result. In this example, I utilize the power of Zend_View which allows me to set up a placeholder within the view or layout and through setting different parameters output the breadcrumbs in a neatly formatted unordered list.
Please note that for the sake of this post this is a very basic implementation of said helper class and therefore should be quite easy to extend. For anyone that would like more information please feel free to leave comments and questions and I’ll get back to you asap.
ALSO, sorry about the formatting. I’m working on it.
Your Helper File:
# ---- File: {library_root}/My/Helper/Breadcrumb.php ----
class My_Helper_Breadcrumb
{
public static function process($crumbs = NULL)
{
if (is_array($crumbs))
{
$count = count($crumbs);
for ($i = 0; $i < $count; $i++)
{
if ($i != ($count - 1))
$output[] = ''. $crumbs[$i]['title'] .'';
else
$output[] = '' . $crumbs[$i]['title'] .'';
}
}
else
{
$output = NULL;
}
return $output;
}
}
Code within your controller:
# Initialize Bread Crumbs Array
$breadcrumbs = array(
array('title' => 'Home', 'url' => '/'),
array('title' => 'Blog', 'url' => '/blog/'));
# Add A Bread Crumb (or Two)
$breadcrumbs[] = array('title' => 'Edit', 'url' => '/blog/edit/');
$breadcrumbs[] = array('title' => $post_name, 'url' => NULL);
# Finalize Bread Crumbs
$this->view->placeholder('breadcrumbs')->exchangeArray( My_Helper_Breadcrumb::process($breadcrumbs) );
Code within your View or Layout
# Format & Display Bread Crumbs
$bc = $this->placeholder('breadcrumbs');
$bc->setPrefix("
\n");
echo $bc;
You can follow the comments for this article with the RSS 2.0 feed.
Content © Tom Milewski
Proudly powered by WordPress
Theme designed by Artisan Themes
20 queries.
0.983 seconds.
exactly what i was looking for
thanks a lot, very much appreciated