带有代码指示器的活动菜单选项卡 [英] Active menu tabs with codeigniter

查看:83
本文介绍了带有代码指示器的活动菜单选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Codeigniter中可以使用哪种方法来实现活动菜单标签?

Which method can be used in Codeigniter to achieve active menu tabs?

例如,我有一个用户菜单 code>

For example I have a user menu Profile Friends Messages Logout

当我在个人资料控制器中时,网址为 domain.com/profile/some_function 个人资料标签应该通过更改背景颜色来激活。

When I'm in the profile controller the URL is domain.com/profile/some_function The Profile tab should be active by changing the background color for example.

我通常添加php到标签以检查其对应的网址段,我将更改活动标签的样式。在Codeigniter应该实现一个帮手?

I would usually add php to the tabs to check for their corresponding URL segment and I would change the style of the active tab. In Codeigniter should I implement a helper? What function can I easily use in tabs?

推荐答案

正如你在最后一段所说的,我只是检查相应的URI

As you said in your last paragraph, I would just check for the corresponding URI segment and change the style of the tab based on that.

让我们假设您使用 foreach 语句从数据库生成菜单:

Let's say you're using a foreach statement to generate your menu from a database:

<ul>
<?php foreach($menu_items as $menu_item):?>   
    <li<?php if($this->uri->segment(2) == url_title($menu_item->name, dash, TRUE)):?> class="active"><?php else:?>><?php endif;?><a href="<?=$menu_item->url;?>"><?=$menu_item->name;?></a></li>
<?php endforeach;?>
</ul>

我把 url_title()要使名称小写,因为URI段将是并且处理可能在菜单名称和/或URI段中的任何可能的空间。这将需要启用URL帮助程序。如果它们不匹配,将使用< li> 元素的默认CSS。

The reason I threw url_title() in there is to make the name lowercase as the URI segment would be and take care of any possible spaces that may be in the menu name and/or URI segment. This would require the URL helper to be enabled. If they don't match, the default CSS for <li> elements would be used.

这篇关于带有代码指示器的活动菜单选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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