从sef url中删除组件部分,菜单项不完全 [英] Remove component part from sef url, menu item not completely

查看:15
本文介绍了从sef url中删除组件部分,菜单项不完全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为 joomla 2.5 构建了一个自定义组件.现在我想实现sef url.所以我开始创建router.php 文件.我几乎成功了.我唯一要更改的是删除组件名称链接.这是我得到的:

I've built a custom component for joomla 2.5. Now i wanted to implement sef urls. So I started to create the router.php file. I was almost successfull. The only thing I want to change is removing the component name link. Here is what I have got:

http://host.tld/component/componentname/

如果我用别名创建菜单项,sef url 如下所示:

If I create a menu item with an alias, the sef url looks like this:

http://host.tld/alias

这是我想要的实际方案,但只有在我单击菜单中的菜单项时才会显示.如果我在主站点,这不起作用.

This is the actual scheme I want to have, but it is only shown when I clicked the menuitem from the menu. If I am at the home site, this does not work.

推荐答案

自己解决了问题:

如果您的组件只有一个菜单项(否则您必须选择正确的菜单项),您只需将这些行添加到您的代码中:

In the case that you have only one menu item for your component (else you have to pick the right one) you just have to add these lines to your code:

$app = JFactory::getApplication();
$menu = $app->getMenu();
$items = $menu->getItems('component', 'com_games');

if (!isset($query['Itemid']))   
    $query['Itemid'] =  $items->id; 

现在 joomla 使用菜单项别名来生成 sef url.

Now joomla takes the menu item alias for generating the sef urls.

这篇关于从sef url中删除组件部分,菜单项不完全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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