ここで重要なのは、適切なメニュー項目を検索して選択するロジックを使用して、コンポーネントのrouter.phpファイル(フロントエンドのコンポーネントのルートフォルダーにあります)をセットアップすることです。私はこれが自動的に起こるのを楽しみにしていますが、私が知る限りではそうではありません。
おそらく、このコードブロックを、コンテンツに最適なメニュー項目を自動的に見つけるために使用できる何らかの種類のヘルパー関数に組み込むのが最善でしょう。
以下は、最適なメニュー項目を取得するためにいくつかのカスタムコンポーネントで使用したコードです。
// I use this first empty array to avoid having unset properties in my query
$base_array = array('Itemid'=>'', 'option'=>'', 'view'=>'', 'layout'=>'', 'id'=>'');
$app =& JFactory::getApplication();
$menu       = $app->getMenu();
$active = $menu->getActive();
// hack to protect the actual current item as well as the search module or other places that use JRoute::_('index.php');
if (count($query)==2 && isset($query['option']) && isset($query['Itemid']) && $query['option'] && $query['Itemid']) {
    return $segments;
}
// start with no match found
$match = false;
$match_level = 0;
$query += $base_array;
// we want to find a menu item for this if possible. If the active menu item is the current menu item then we should see if there is a better match.
if (empty($query['Itemid']) || ($query['Itemid'] == $active->id && empty($query['task']))) {
    // load all menu items
    $items = $menu->getMenu();
    // use the current item over others if it ties for the best match
    if ($active->query['option'] == $query['option']) {
        $match_level = 1;
        $match = $active;
        if ($active->query['view'] == $query['view']) {
            $match_level = 2;
            if ($active->query['layout'] == $query['layout'] || ($query['layout']=='default' && !$active->query['layout'])) {
                $match_level = 3;
                if ($active->query['id'] == $query['id']) {
                    $match_level = 4;
                }
            }
        }
    }
    // loop through each menu item in order
    foreach ($items as $item) {
        $item->query += $base_array;
        // base check is that it is for this component
        // then cycle through each possibility finding it's match level
        if ($item->query['option'] == $query['option']) {
            $item_match = 1;
            if ($item->query['view'] == $query['view']) {
                $item_match = 2;
                if (!$query['layout'] && $item->query['layout']) {
                    $query['layout'] = 'default';
                }
                if ($item->query['layout'] == $query['layout'] || ($query['layout']=='default' && !$item->query['layout'])) {
                    $item_match = 3;
                    if ($item->query['id'] == $query['id']) {
                        $item_match = 4;
                    }
                }
            }
        }
        // if this item is a better match than our current match, set it as the best match
        if ($item_match > $match_level) {
            $match = $item;
            $match_level = $item_match;
        }
    }
    // if there is a match update Itemid to match that menu item
    if ($match) {
        $query['Itemid'] = $match->id;
        $menuItem = $menu->getItem($match->id);
    } else {
        $menuItem = $menu->getActive();
    }
}
これはすべて一種の混乱です(そして、もし誰かがそれらを持っているなら、私は改善が大好きです!)、それは仕事を終わらせます。現在のメニュー項目が最良の一致である場合、常にそれが維持されます。
それ以外の場合は、コンポーネント名->ビュー名->レイアウト名-> id値に基づいて最適な一致を見つける必要があります。一致するほど右にあるほど、一致すると判断します。