Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CakePHP:如何制作动态导航栏_Php_Cakephp_Hyperlink_Cakephp 1.3_Navigationbar - Fatal编程技术网

CakePHP:如何制作动态导航栏

CakePHP:如何制作动态导航栏,php,cakephp,hyperlink,cakephp-1.3,navigationbar,Php,Cakephp,Hyperlink,Cakephp 1.3,Navigationbar,我的网站上有导航栏,如: 下面是我的代码: <ul class="breadcrumb"> <li> <i class="icon-home"></i> <a href="index.html">Home</a> <i class="icon-angle-right"><

我的网站上有导航栏,如:

下面是我的代码:

        <ul class="breadcrumb">
            <li>
                <i class="icon-home"></i>
                <a href="index.html">Home</a> 
                <i class="icon-angle-right"></i>
            </li>
            <li>
            <?php echo $this->Html->link($title_for_layout,array('controller'=>'controllers','action'=>'index','full_base'=>true));?>
            </li>
        </ul>
在这张图片中,我正在与员工控制器合作。所以我的链接是“主页>员工”。如果我使用产品控制器链接将是“主页>产品”

  • 但如果我与员工控制员一起工作,行动就是添加。指“员工/添加”。我想在导航栏上显示它,如“主页>员工>添加”。那我该怎么做呢

  • 如果我做了#1。当前链接将是“主页>员工>添加”。当我想回到员工索引的时候。我点击“主页>员工>添加”中的“员工”。我必须让里面的链接像

    $this->Html->link($title\u用于布局、数组('controller'=>'staff','action'=>'index'))

  • 当与员工控制器一起工作时,此链接是可以的。当我更改为产品时,客户将断开此链接。我如何才能创建它

    我使用的是CakePHP1.3
    很抱歉,我问了这么简单的问题。我是Cake PHP新手。感谢您的帮助和阅读。

    您需要以结构化的方式开始解决这个问题。您需要收集一个包含所有要显示在面包屑中的链接的数组,然后遍历并输出所有链接。尝试以下方法:

    $links = array();
    // Add the home URL
    $links[] = array(
        'icon' => 'icon-home',
        'title' => 'Home',
        'url' => 'index.html'
    );
    
    // Add the controller
    $links[] = array(
        'title' => ucwords($this->params['controller']),
        'url' => $this->Html->url(array('controller' => $this->params['controller'], 'action' => 'index', 'full_base' => true))
    );
    
    // Now, conditionally add the next parts where necessary
    
    $param1 = isset($this->params['pass'][0]) ? $this->params['pass'][0] : null;
    if($param1) {
        $links[] = array(
            'title' => ucwords($param1),
            'url' => $this->Html->url(array('controller' => $this->params['controller'], 'action' => $this->action, $param1))
        );
    }
    
    <ul class="breadcrumb">
        <?php
        $size = count($links);
        foreach($links as $i => $link) : ?>
            <li>
                <?php
                // Output icon if it's set
                if(isset($link['icon']))
                    echo '<i class="' . $link['icon'] . '"></i>'; ?>
    
                // Output the link itself
                echo $this->Html->link($link['title'], $link['url']);
    
                // Output the caret if necessary (it's not the last)
                if($i < $size - 1)
                    echo '<i class="icon-angle-right"></i>';
                ?>
            </li>
        <?php endforeach; ?>
    </ul>
    
    现在,您有了一个包含要输出的三个链接的结构化数组,因此您可以像这样轻松地输出它们:

    $links = array();
    // Add the home URL
    $links[] = array(
        'icon' => 'icon-home',
        'title' => 'Home',
        'url' => 'index.html'
    );
    
    // Add the controller
    $links[] = array(
        'title' => ucwords($this->params['controller']),
        'url' => $this->Html->url(array('controller' => $this->params['controller'], 'action' => 'index', 'full_base' => true))
    );
    
    // Now, conditionally add the next parts where necessary
    
    $param1 = isset($this->params['pass'][0]) ? $this->params['pass'][0] : null;
    if($param1) {
        $links[] = array(
            'title' => ucwords($param1),
            'url' => $this->Html->url(array('controller' => $this->params['controller'], 'action' => $this->action, $param1))
        );
    }
    
    <ul class="breadcrumb">
        <?php
        $size = count($links);
        foreach($links as $i => $link) : ?>
            <li>
                <?php
                // Output icon if it's set
                if(isset($link['icon']))
                    echo '<i class="' . $link['icon'] . '"></i>'; ?>
    
                // Output the link itself
                echo $this->Html->link($link['title'], $link['url']);
    
                // Output the caret if necessary (it's not the last)
                if($i < $size - 1)
                    echo '<i class="icon-angle-right"></i>';
                ?>
            </li>
        <?php endforeach; ?>
    </ul>
    

    • 谢谢你的回答,但也许我还不够了解。我会研究一下。