gpt4 book ai didi

php - 如何在 CakePhp 的当前页面中添加事件类

转载 作者:可可西里 更新时间:2023-11-01 13:06:26 24 4
gpt4 key购买 nike

我有一个类似这个问题的问题

How to identify active menu link in CakePHP

我的 default.ctp 文件中有一个页面,我想在其中的链接上添加“事件”类。我如何识别页面的当前 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''>

最佳答案

这是一个简单的逻辑如下

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

关于php - 如何在 CakePhp 的当前页面中添加事件类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17161982/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com