我一直在阅读此链接 Active menu tabs with codeigniter ,它可以工作,但是如果像这样的链接 domain.com/mycontroller/myfunction/id
例如 menu A
-> domanin.com/A/a/1
, menu A
-> domanin.com/A/b/1
等。高亮事件类在“A” Controller 上。
谢谢
已编辑
下面是我的模板 View 代码
<?php foreach ($menu as $row): ?>
<li <?php if($this->uri->uri_string(2) == url_title($row->menu,'/detail_product/',TRUE)):?>class="active"<?php endif;?>><?php echo anchor('/'.$row->link,$row->menu); ?></li>
<?php endforeach; ?>
这里是我的 Controller 代码
public function index()
{
$data['content'] = 'home/garagebox';
$data['menu'] = $this->auction_model->load_menu();
$this->load->view('template',$data);
}
我的菜单是这样的,
主页 |拍卖 |新闻
我有产品,当我选择一个时,它会指向此链接 http://domain.com/index.php/auction/detail_product/1
因为此链接位于“拍卖”菜单下,所以拍卖菜单应该突出显示
最佳答案
链接 1 |链接 2 | ...
首先,您需要在 Controller 文件中设置一个变量。
$data['selected_menu'] = 'link1';
$this->load->view('your view file',$data); //and send $data variable to your view file.
在查看文件中,您只需检查值:
if($selected_menu == 'link1')
//highlight link.
与所有 Controller 相同,即方法/函数。
关于css - 事件的 CSS 菜单选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13152874/