PHP 痕迹导航数组,链接未满

我为面包屑使用以下代码:


<?php


class Breadcrumb

{

   private $breadcrumb;

   private $separator = ' / ';

   private $domain = 'example.org';


   public function build($array)

   {

      $breadcrumbs = array_merge(array('Home' => ''), $array);

      $count = 0;

      foreach($breadcrumbs as $title => $link) {

         $this->breadcrumb .= '

         <span itemscope="" itemtype="https://schema.org/BreadcrumbList">

            <a href="'.$this->domain. '/'.$link.'" itemprop="url">

               <span itemprop="title">'.$title.'</span>

            </a>

         </span>';


         $count++;

         if($count !== count($breadcrumbs)) {

            $this->breadcrumb .= $this->separator;

         }

      }

      return $this->breadcrumb;

   }

}


 ?>

我这样称呼它:


<?php

$breadcrumb = new Breadcrumb();

  echo $breadcrumb->build(array(

  $pageTitle => 'about',

    'More' => 'more.php'

  )); 

?>

页面标题是每个页面顶部的变量。


输出是正确的,并显示:首页 / 关于 / 更多 但是,每个上的链接如下所示:


Home: example.org

About: example.org/about

More: example.org/more.php

我正在寻找这样的输出:example.org/about/more.php


繁花如伊
浏览 86回答 1
1回答

波斯汪

您可以在循环中连接链接...$bclink = '';foreach($breadcrumbs as $title => $link) {&nbsp; &nbsp; if ($link != '') {&nbsp; &nbsp; &nbsp; &nbsp; $bclink .= '/' . $link;&nbsp; &nbsp; }&nbsp; &nbsp; $this->breadcrumb .= '&nbsp; &nbsp; &nbsp; &nbsp; <span itemscope="" itemtype="https://schema.org/BreadcrumbList">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="'.$this->domain.$bclink.'" itemprop="url">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span itemprop="title">'.$title.'</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </a>&nbsp; &nbsp; &nbsp; &nbsp; </span>';&nbsp; &nbsp; $count++;&nbsp; &nbsp; if($count !== count($breadcrumbs)) {&nbsp; &nbsp; &nbsp; &nbsp; $this->breadcrumb .= $this->separator;&nbsp; &nbsp; }}
打开App,查看更多内容
随时随地看视频慕课网APP