dsxz84851 2016-12-13 23:00 采纳率: 100%
浏览 99
已采纳

包含返回上一个文件夹的链接的面包屑

Today we are in the process of making a file manager script for our new hosting control panel interface and we want to make breadcrumbs that the user can click on to go back to the path before it. So far they show up like this

navbits

Looks alright I suppose. The first three links are static and never change, and the farther off the /home that the user goes, the more links are added to the breadcrumb. Right now if you were in a directory like we are here aka /home/www/usr/ then the url looks something like this:

/filemanager.php?do=browse&dir=www/usr

Then we explode the $_GET['dir'] between all the items separated by a / and add them into an array. Then we loop through the array and foreach one we print out an <li>$i</li> into the breadcrumb area.

The problem now, is how can we make the links for each item in the menu keep its parent folder and / if it has one? When a user clicks on www in this example, it works because it's the same link as the name, but any child li needs www/ added to the front, and any other parents as well. A bit stumped here.

Here's the LI adding process we are using:

if(isset($_GET['dir']) && !empty($_GET['dir'])) {
    $breadcrumb_list = array();
    $breadcrumb_list = explode("/", $_GET['dir']);
    echo "<li><a href=\"filemanager?do=browse\">Home</a></li>
";
    foreach($breadcrumb_list as $i) {
        echo "<li><a href=\"filemanager?do=browse&amp;dir={$i}\">{$i}</a></li>
";
    }
}

Any and all help will be appreciated! Thanks guys!

  • 写回答

1条回答 默认 最新

  • duanji9378 2016-12-13 23:57
    关注

    Before foreach loop create new variable eg

    $path = '';
    

    Then in every iteration add current part of path:

    $path .= '/'.$i;
    

    So it will looks like that:

    $path = '';
    foreach($breadcrumb_list as $i) {
        $path .= '/'.$i;
        echo "<li><a href=\"filemanager?do=browse&amp;dir={$path}\">{$i}</a></li>
    ";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献