我有一个类似于这个问题的问题。
我在default.ctp文件中有一个页面,我想在链接上添加'active'类。我如何识别当前页面的URL,然后在链接上应用该类。我已经按照那里的答案进行了操作,答案是:
$url = $this->Html->url('INPUT_THE_URL') ;
$active = $this->request->here == $url? true: false;
我不知道该如何在我的代码中实现这个功能。非常抱歉向您提问,因为我是一个 CakePHP 新手。以下是我的代码:
**default.ctp file**
<li>
<?php echo $this->Html->link('Dashboard', array('controller'=>'users','action' => 'controlpanel'), array('title' => 'Dashboard','class' => 'shortcut-dashboard'));?></li>
<li> <?php echo $this->Html->link('Contacts', array('controller'=>'contacts','action' => 'index'), array('title' => 'Contacts','class' => 'shortcut-contacts'));?></li>
我想给像这样的li元素添加一个类:
<li class = 'active''>