如何在CakePHP的当前页面中添加活动类 [英] how to add active class in current page in CakePhp

查看:180
本文介绍了如何在CakePHP的当前页面中添加活动类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类似这个问题的问题

i have a problem similar to this question

如何识别CakePHP中的活动菜单链接

我在我的default.ctp文件中有一个页面,其中i想在链接上添加活动类。如何识别页面的当前网址,然后应用链接上的类..我已经跟着的答案也是

i have a page in my default.ctp file in which i want to add 'active' class on links. how can i identify the current url of the page and then apply the class on link.. i have followed the answer also there which is

      $url = $this->Html->url('INPUT_THE_URL') ;
     $active = $this->request->here == $url? true: false;

我不知道如何在我的代码中这样做..对不起,因为我是新手cakephp ..这里是我的代码

i dont know how can i do this in my code .. sorry for asking as i am newbie in cakephp .. here is my code

 **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>

我想添加一个类似这样的类

i want to add a class with li like this

   <li class = 'active''>


推荐答案

这是一个简单的逻辑如下

This is a simple logic as follows

<li class="<?php echo (!empty($this->params['action']) && ($this->params['action']=='controlpanel') )?'active' :'inactive' ?>">
  <?php echo $this->Html->link('Dashboard', array('controller'=>'users','action' => 'controlpanel'), array('title' => 'Dashboard','class' => 'shortcut-dashboard'));?>
</li>

<li class="<?php echo (!empty($this->params['action']) && ($this->params['action']=='index') )?'active' :'inactive' ?>">
  <?php echo $this->Html->link('Contacts', array('controller'=>'contacts','action' => 'index'), array('title' => 'Contacts','class' => 'shortcut-contacts'));?></li>

这篇关于如何在CakePHP的当前页面中添加活动类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆