Home > Zend Framework > Zend Framework:: Helper method for creating breadcrumbs

Zend Framework:: Helper method for creating breadcrumbs

Here I am going to show how one can create breadcrumbs in the web application based on Zend Framework. This can be achieved by creating a helper method. Before creating helper method, we need to do the following exercise:

  • Create Zend view object,
  • Add view script path,
  • Add the default helper path to the view object,

Now lets start step by step:

Creating Zend view object:

$view = Zend_View();

Adding view script path:

$viewPath = “path/to/viewsDirectory”;

Adding the default helper path to the vew object:

$helperPath = “path/to/helperDirectory”;      Zend_Controller_Action_HelperBroker::getStaticHelper(‘viewRenderer’)->setView($view);
$view->addHelperPath($helperPath, ‘Helper_’);

Now creating the class for the breadcrumbs:

class Helper_BreadCrumbs {

public function breadCrumb(){
$cFront = Zend_Controller_Front::getInstance();
$module = $cFront->getRequest()->getModuleName();
$module = strtolower($module);

$controller = $cFront->getRequest()->getControllerName();
$controller = strtolower($controller);

$action = $cFront->getRequest()->getActionName();
$action = strtolower($action);

if($module == “default” && $controller == “index” && $action == “index”){
//Home link
$home = ‘<a href=”/”>Home</a>’;

//start breadcrumbs
$bCrumbs = $home . “::”;
if($action == “index”){
$bCrumbs .= $controller;
$bCrumbs .= “<a href=’/$controller’>$controller</a>::
<a href=’/$controller/$action’>$action</a>”;

return $bCrumbs;

Hope this article will help the web application users to indicate “where are you”.

Categories: Zend Framework
  1. July 19, 2010 at 1:52 pm

    Thanks a bunch! Your solution is quite much what I was thinking on creating, though it lacks some functionality for the last tier. For an example, if I wanted to display it like this:


    If I get some spare time, I’ll try to incorporate such a functionality.

  2. Adeel Ahmad Rao
    February 7, 2012 at 9:33 am

    Appreciable.. Good to use for dynamic breadcrumbs.. Many Thanks 🙂

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: