2016-05-04 58 views
-1

中创建具有锚点形式url的面包屑,用于filemanagement系统我想在url中通过php创建一些面包屑。 每个用户的根目录是看起来像这样的网址:如何在php

example.com/sfm?dir=uploads/sfm/root 

在ROOTDIR有一个名为folder1 当文件夹1点击文件夹,网址是:

example.com/sfm?dir=uploads/sfm/root/folder1 

在文件夹1有一个名为folder2 当该文件夹上单击文件夹,则网址:

example.com/sfm?dir=uploads/sfm/root/folder1/folder2 

等等... 我如何制作一些面包屑锚点到基于网址的文件夹?

回答

1

如果我正确地理解了你,你想要做的就是参加$_GET['dir']的争夺,并将它们拆分为/,然后为每个人提供链接。

这里是我会怎么做:

$crumbs=explode('/',$_GET['dir']); // this splits the sections of $_GET['dir'] separated by/into an array of values 
$url_pre=''; // we'll use this to keep track of the crumbs we've sifted through already 

// foreach cycles through each element in an array 
// $crumbs is the array, and $crumb is the current listing in the array we're looking at 
foreach($crumbs as $crumb){ 
    $url_pre.=.$crumb; 
    echo '<a href="?dir='.$url_pre.'">'.$crumb.'</a>'; 
    $url_pre.='/'; // add this after you echo the link, so that dir doesn't start with a/
} 
+0

测试,它的伟大工程!感谢您的解决方案。 (小错字:'$ url_pre。=。$ crumb;'应该是'$ url_pre。= $ crumb;') –