TbHtml::breadcrumbs PHP Method

breadcrumbs() public static method

Generates a breadcrumb menu.
public static breadcrumbs ( array $links, array $htmlOptions = [] ) : string
$links array the breadcrumb links.
$htmlOptions array additional HTML attributes.
return string the generated breadcrumb.
    public static function breadcrumbs($links, $htmlOptions = array())
    {
        self::addCssClass('breadcrumb', $htmlOptions);
        $output = self::openTag('ol', $htmlOptions);
        foreach ($links as $label => $url) {
            if (is_string($label)) {
                $output .= self::openTag('li');
                $output .= self::link($label, $url);
                $output .= '</li>';
            } else {
                $output .= self::tag('li', array('class' => 'active'), $url);
            }
        }
        $output .= '</ol>';
        return $output;
    }

Usage Example

Example #1
0
 /**
  * Runs the widget.
  */
 public function run()
 {
     // todo: consider adding control property for displaying breadcrumbs even when empty.
     if (!empty($this->links)) {
         $links = array();
         if ($this->homeLabel !== false) {
             $label = $this->homeLabel !== null ? $this->homeLabel : TbHtml::icon('home');
             $links[$label] = $this->homeUrl !== null ? $this->homeUrl : Yii::app()->homeUrl;
         }
         foreach ($this->links as $label => $url) {
             if (is_string($label) || is_array($url)) {
                 if ($this->encodeLabel) {
                     $label = CHtml::encode($label);
                 }
                 $links[$label] = $url;
             } else {
                 $links[] = $this->encodeLabel ? CHtml::encode($url) : $url;
             }
         }
         echo TbHtml::breadcrumbs($links, $this->htmlOptions);
     }
 }
All Usage Examples Of TbHtml::breadcrumbs
TbHtml