From 52c9c9e3198b73e10a48660bcfb5282d2957a0a5 Mon Sep 17 00:00:00 2001 From: pzinovkin Date: Sat, 27 Mar 2010 17:37:52 +0000 Subject: [PATCH] Breadcrumb view helper, #16 git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@138 4cb57b5f-5bbd-dd11-951b-001d605cbbc5 --- view/helpers/ViewHelperBreadcrumb.php | 52 +++++++++++++++++++++++++++++++++++ view/helpers/ViewHelperTitle.php | 9 +++++- 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 view/helpers/ViewHelperBreadcrumb.php diff --git a/view/helpers/ViewHelperBreadcrumb.php b/view/helpers/ViewHelperBreadcrumb.php new file mode 100644 index 0000000..96aeb6b --- /dev/null +++ b/view/helpers/ViewHelperBreadcrumb.php @@ -0,0 +1,52 @@ + + * @link http://netmonsters.ru + * @package Majestic + * @subpackage View + * @since 2010-03-16 + * @version SVN: $Id$ + * @filesource $URL$ + */ + +class ViewHelperBreadcrumb extends ViewHelper +{ + + protected $separator = ' > '; + + public function breadcrumb($text = false, $href = false) + { + if ($text) { + $this->append($text, $href); + } + return $this; + } + + public function prepend($text, $href) + { + Registry::set(__CLASS__, array($text => $href) + Registry::get(__CLASS__, array())); + } + + public function append($text, $href) + { + Registry::set(__CLASS__, Registry::get(__CLASS__, array()) + array($text => $href)); + } + + public function setSeparator($sep) + { + $this->separator = $sep; + } + + public function __toString() + { + $data = array(); + foreach (Registry::get(__CLASS__, array()) as $text => $href) { + if ($href) { + $data[] = '' . $this->view->escape($text) . ''; + } else { + $data[] = $this->view->escape($text); + } + } + return implode($this->separator, $data); + } +} \ No newline at end of file diff --git a/view/helpers/ViewHelperTitle.php b/view/helpers/ViewHelperTitle.php index 19dffcd..4b988fe 100644 --- a/view/helpers/ViewHelperTitle.php +++ b/view/helpers/ViewHelperTitle.php @@ -12,6 +12,8 @@ class ViewHelperTitle extends ViewHelper { + protected $separator = ' - '; + public function title($string = false) { if ($string) { @@ -22,8 +24,13 @@ class ViewHelperTitle extends ViewHelper return $this; } + public function setSeparator($sep) + { + $this->separator = $sep; + } + public function __toString() { - return implode(' - ', Registry::get(__CLASS__, array())); + return implode($this->separator, Registry::get(__CLASS__, array())); } } \ No newline at end of file