Browse Source

Breadcrumb view helper, #16

git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@138 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
master
pzinovkin 15 years ago
parent
commit
52c9c9e319
  1. 52
      view/helpers/ViewHelperBreadcrumb.php
  2. 9
      view/helpers/ViewHelperTitle.php

52
view/helpers/ViewHelperBreadcrumb.php

@ -0,0 +1,52 @@
<?php
/**
* @copyright NetMonsters <team@netmonsters.ru>
* @link http://netmonsters.ru
* @package Majestic
* @subpackage View
* @since 2010-03-16
* @version SVN: $Id$
* @filesource $URL$
*/
class ViewHelperBreadcrumb extends ViewHelper
{
protected $separator = ' &gt; ';
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[] = '<a href="' . $this->view->escape($href) . '">' . $this->view->escape($text) . '</a>';
} else {
$data[] = $this->view->escape($text);
}
}
return implode($this->separator, $data);
}
}

9
view/helpers/ViewHelperTitle.php

@ -12,6 +12,8 @@
class ViewHelperTitle extends ViewHelper class ViewHelperTitle extends ViewHelper
{ {
protected $separator = ' - ';
public function title($string = false) public function title($string = false)
{ {
if ($string) { if ($string) {
@ -22,8 +24,13 @@ class ViewHelperTitle extends ViewHelper
return $this; return $this;
} }
public function setSeparator($sep)
{
$this->separator = $sep;
}
public function __toString() public function __toString()
{ {
return implode(' - ', Registry::get(__CLASS__, array()));
return implode($this->separator, Registry::get(__CLASS__, array()));
} }
} }
Loading…
Cancel
Save