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.

49 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. */
  9. class BreadcrumbViewHelper extends ViewHelper
  10. {
  11. protected $separator = ' &gt; ';
  12. public function breadcrumb($text = false, $href = false)
  13. {
  14. if ($text) {
  15. $this->append($text, $href);
  16. }
  17. return $this;
  18. }
  19. public function prepend($text, $href)
  20. {
  21. Registry::set(__CLASS__, array($text => $href) + Registry::get(__CLASS__, array()));
  22. }
  23. public function append($text, $href)
  24. {
  25. Registry::set(__CLASS__, Registry::get(__CLASS__, array()) + array($text => $href));
  26. }
  27. public function setSeparator($sep)
  28. {
  29. $this->separator = $sep;
  30. }
  31. public function __toString()
  32. {
  33. $data = array();
  34. foreach (Registry::get(__CLASS__, array()) as $text => $href) {
  35. if ($href) {
  36. $data[] = '<a href="' . $this->view->escape($href) . '">' . $this->view->escape($text) . '</a>';
  37. } else {
  38. $data[] = $this->view->escape($text);
  39. }
  40. }
  41. return implode($this->separator, $data);
  42. }
  43. }