Created
January 14, 2012 12:25
-
-
Save fullybaked/1611253 to your computer and use it in GitHub Desktop.
Enhanced HtmlHelper::getCrumbs() from CakePHP 2.x to allow custom first link url and passing of images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
/** | |
* Returns the breadcrumb trail as a sequence of »-separated links. | |
* | |
* @param string $separator Text to separate crumbs. | |
* @param string $startText This will be the first crumb, if false it defaults to first crumb in array | |
* @param mixed $startPath Url for the first link in the bread crumbs, can be a string or array | |
* @param boolean $escape Escape the content of the link text, set to false if passing an image in | |
* @return string Composed bread crumbs | |
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#creating-breadcrumb-trails-with-htmlhelper | |
*/ | |
public function getCrumbs($separator = '»', $startText = false, $startPath = '/', $escape = true) { | |
if (!empty($this->_crumbs)) { | |
$out = array(); | |
if ($startText) { | |
$out[] = $this->link($startText, $startPath, array('escape' => $escape)); | |
} | |
foreach ($this->_crumbs as $crumb) { | |
if (!empty($crumb[1])) { | |
$out[] = $this->link($crumb[0], $crumb[1], $crumb[2]); | |
} else { | |
$out[] = $crumb[0]; | |
} | |
} | |
return join($separator, $out); | |
} else { | |
return null; | |
} | |
} |
Yeah, this was a quickly put together solution. Mark Story suggested overloading the $startText parameter as another alternative, in the thread regarding this on Lighthouse..
In fact its been added to 2.1 cakephp/cakephp@c89c49c
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would it not be better to place this support inside of the options array?