Remove component part from sef url, menu item not completely

丶灬走出姿态 提交于 2019-12-02 17:23:34

问题


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/

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.


回答1:


Solved the problem myself:

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; 

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



来源:https://stackoverflow.com/questions/12887099/remove-component-part-from-sef-url-menu-item-not-completely

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!