You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.2 KiB

  1. <?php
  2. /**
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage View
  7. * @since 2010-03-16
  8. * @version SVN: $Id$
  9. * @filesource $URL$
  10. */
  11. class BreadcrumbViewHelper extends ViewHelper
  12. {
  13. protected $separator = ' &gt; ';
  14. public function breadcrumb($text = false, $href = false)
  15. {
  16. if ($text) {
  17. $this->append($text, $href);
  18. }
  19. return $this;
  20. }
  21. public function prepend($text, $href)
  22. {
  23. Registry::set(__CLASS__, array($text => $href) + Registry::get(__CLASS__, array()));
  24. }
  25. public function append($text, $href)
  26. {
  27. Registry::set(__CLASS__, Registry::get(__CLASS__, array()) + array($text => $href));
  28. }
  29. public function setSeparator($sep)
  30. {
  31. $this->separator = $sep;
  32. }
  33. public function __toString()
  34. {
  35. $data = array();
  36. foreach (Registry::get(__CLASS__, array()) as $text => $href) {
  37. if ($href) {
  38. $data[] = '<a href="' . $this->view->escape($href) . '">' . $this->view->escape($text) . '</a>';
  39. } else {
  40. $data[] = $this->view->escape($text);
  41. }
  42. }
  43. return implode($this->separator, $data);
  44. }
  45. }