面包屑链接未显示正确的URL

时间:2017-08-09 09:05:01

标签: codeigniter

我正在为我的文件夹创建一些面包屑。当我点击第二个面包屑链接时,它没有转到正确的URL

之前的网址显示“test”

http://localhost/project/admin/common/test?directory=test/sub

它应该显示

http://localhost/project/admin/common/test?directory=test

检查员输出

<ul class="breadcrumb">
    <li><a href="http://localhost/project/admin/common/test">Catalog</a></li>
    <li><a href="http://localhost/project/admin/common/test?directory=test/sub">test</a></li>
    <li><a href="http://localhost/project/admin/common/test?directory=test/sub">sub</a></li>
</ul>

在视图

<ul class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <li><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a></li>
    <?php } ?>
</ul>
  

问题:如何确保以前的网址显示之前文件夹的正确网址。

我在控制器上生成面包屑

$data['breadcrumbs'] = array();

$data['breadcrumbs'][] = array(
    'text' => 'Catalog',
    'href' => base_url('admin/common/test')
);

$directory_names = explode('/', $this->input->get('directory'));

foreach ($directory_names as $directory_name) {
    $data['breadcrumbs'][] = array(
        'text' => $directory_name,
        'href' => base_url('admin/common/test?directory=' . $this->input->get('directory'))
    );
}

enter image description here

1 个答案:

答案 0 :(得分:0)

感谢我现在在另一个论坛上发现的解决方案,我将在此处发帖分享

https://forum.codeigniter.com/thread-68653-post-346110.html#pid346110

$directory_names = explode('/', $this->input->get('directory'));

$directory_done = '';

foreach ($directory_names as $directory_name) {
        $directory_done .= ($directory_done <> ''? '/':'').$directory_name; 
    $data['breadcrumbs'][] = array(
        'text' => $directory_name,
        'href' => base_url('admin/common/test?directory=' . $directory_done)
    );
}