Cake\View\Helper\HtmlHelper::getCrumbList PHP Метод

getCrumbList() публичный Метод

This method uses HtmlHelper::tag() to generate list and its elements. Works similar to HtmlHelper::getCrumbs(), so it uses options which every crumb was added with. ### Options - separator Separator content to insert in between breadcrumbs, defaults to '' - firstClass Class for wrapper tag on the first breadcrumb, defaults to 'first' - lastClass Class for wrapper tag on current active page, defaults to 'last'
Устаревший: 3.3.6 Use the BreadcrumbsHelper instead
public getCrumbList ( array $options = [], string | array | boolean $startText = false ) : string | null
$options array Array of HTML attributes to apply to the generated list elements.
$startText string | array | boolean This will be the first crumb, if false it defaults to first crumb in array. Can also be an array, see `HtmlHelper::getCrumbs` for details.
Результат string | null Breadcrumbs HTML list.
    public function getCrumbList(array $options = [], $startText = false)
    {
        $defaults = ['firstClass' => 'first', 'lastClass' => 'last', 'separator' => '', 'escape' => true];
        $options += $defaults;
        $firstClass = $options['firstClass'];
        $lastClass = $options['lastClass'];
        $separator = $options['separator'];
        $escape = $options['escape'];
        unset($options['firstClass'], $options['lastClass'], $options['separator'], $options['escape']);
        $crumbs = $this->_prepareCrumbs($startText, $escape);
        if (empty($crumbs)) {
            return null;
        }
        $result = '';
        $crumbCount = count($crumbs);
        $ulOptions = $options;
        foreach ($crumbs as $which => $crumb) {
            $options = [];
            if (empty($crumb[1])) {
                $elementContent = $crumb[0];
            } else {
                $elementContent = $this->link($crumb[0], $crumb[1], $crumb[2]);
            }
            if (!$which && $firstClass !== false) {
                $options['class'] = $firstClass;
            } elseif ($which == $crumbCount - 1 && $lastClass !== false) {
                $options['class'] = $lastClass;
            }
            if (!empty($separator) && $crumbCount - $which >= 2) {
                $elementContent .= $separator;
            }
            $result .= $this->formatTemplate('li', ['content' => $elementContent, 'attrs' => $this->templater()->formatAttributes($options)]);
        }
        return $this->formatTemplate('ul', ['content' => $result, 'attrs' => $this->templater()->formatAttributes($ulOptions)]);
    }

Usage Example

 /**
  *
  * Get crumb lists in a HTML list, with bootstrap like style.
  *
  * @param $options Options for list
  * @param $startText Text to insert before list
  *
  * Unusable options:
  * 	- Separator
  **/
 public function getCrumbList(array $options = array(), $startText = false)
 {
     $options['separator'] = '';
     $options = $this->addClass($options, 'breadcrumb');
     return parent::getCrumbList($options, $startText);
 }
All Usage Examples Of Cake\View\Helper\HtmlHelper::getCrumbList