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

查看:111
本文介绍了从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天全站免登陆