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>
-
-
在这张图片中,我正在与员工控制器合作。所以我的链接是“主页>员工”。如果我使用产品控制器链接将是“主页>产品”
很抱歉,我问了这么简单的问题。我是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>
-
谢谢你的回答,但也许我还不够了解。我会研究一下。