2014-03-01 57 views
0

活躍狀態我與Joomla 3的Joomla 3菜單不工作

一個問題,我讓菜單使用自定義模板位於/templates/mytemplate/html/mod_menu/mainmenu.php

但當我進入菜單中的任何鏈接時,「活動」數組索引始終爲false。

例如,CURENT頁是http://localhost/about.html

和陣列中的「活躍」指數是空

[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] => 
     ) 
+0

你能提供'/ templates/mytemplate/html/mod_menu/mainmenu.php'的代碼嗎? – Lodder

回答

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->activetrue,如果你想要的。但是,那時你可能只是完成了你想要的東西!

+0

非常感謝你! – Vladimir

+0

如果這回答您的問題,請點擊答案左側的複選標記接受答案。 :) –