Joomla 3菜单活动状态不起作用

时间:2014-03-01 20:35:23

标签: php joomla

我对joomla 3有疑问。

我使用自定义模板制作的菜单位于/templates/mytemplate/html/mod_menu/mainmenu.php

但是当我继续菜单中的任何链接时,“active”的数组索引始终为false。

例如,curent页面为http://localhost/about.html

并且在数组中“active”索引为空

[1] => stdClass Object
        (
            [id] => 102
            [menutype] => mainmenu
            [title] => О проекте
            [alias] => about
            [note] => 
            [route] => about
            [link] => index.php?option=com_content&view=article&id=1
            [type] => component
            [level] => 1
            [language] => *
            [browserNav] => 0
            [access] => 1
            [params] => JRegistry Object
                (
                    [data:protected] => stdClass Object
                        (
                            [show_title] => 
                            [link_titles] => 
                            [show_intro] => 
                            [info_block_position] => 
                            [show_category] => 
                            [link_category] => 
                            [show_parent_category] => 
                            [link_parent_category] => 
                            [show_author] => 
                            [link_author] => 
                            [show_create_date] => 
                            [show_modify_date] => 
                            [show_publish_date] => 
                            [show_item_navigation] => 
                            [show_vote] => 
                            [show_tags] => 
                            [show_icons] => 
                            [show_print_icon] => 
                            [show_email_icon] => 
                            [show_hits] => 
                            [show_noauth] => 
                            [urls_position] => 
                            [menu-anchor_title] => 
                            [menu-anchor_css] => 
                            [menu_image] => 
                            [menu_text] => 1
                            [page_title] => 
                            [show_page_heading] => 0
                            [page_heading] => 
                            [pageclass_sfx] => 
                            [menu-meta_description] => 
                            [menu-meta_keywords] => 
                            [robots] => 
                            [secure] => 0
                        )

                )

            [home] => 0
            [img] => 
            [template_style_id] => 0
            [component_id] => 22
            [parent_id] => 1
            [component] => com_content
            [tree] => Array
                (
                    [0] => 102
                )

            [query] => Array
                (
                    [option] => com_content
                    [view] => article
                    [id] => 1
                )

            [deeper] => 
            [shallower] => 
            [level_diff] => 0
            [parent] => 
this empty  [active] =>
            [flink] => /about.html
            [anchor_css] => 
            [anchor_title] => 
            [menu_image] => 
        )

1 个答案:

答案 0 :(得分:1)

从基础mod_menu文件的外观来看,活动属性始终由加载菜单的帮助程序设置为false,而是使用自己的检查来查看活动的内容。也就是说,基础mod_menu.php文件设置这些值:

$list       = ModMenuHelper::getList($params);
$base       = ModMenuHelper::getBase($params);
$active     = ModMenuHelper::getActive($params);
$active_id  = $active->id;
$path       = $base->tree;

所以active_id将包含当前菜单项的id。因此,如果您想要当前菜单,可以这样检查:

foreach ($list as $i => &$item) :
if ($item->id == $active_id) {
        // do something with active item
    }
    ....
}

$list由主文件设置,因此可以在布局文件中访问。

您还可以使用此检查检查同一foreach循环中活动项目上方的父项:

if (in_array($item->id, $path)) {}

从技术上讲,如果您愿意,可以运行第一个foreach循环并将$item->active设置为true。但是,那时你可能只是用项目做了你想做的事情!