Extend the JRoute API?

by ranwilli   Last Updated June 07, 2017 13:10 PM

there is a helper coded:

JRoute::_(ContentHelperRoute::getCategoryRoute($item->id, $item->language))

It does precisely what I want it to do, but I need the same functionality for the "Featured" View...

Ideas?



Answers 1


getCategoryRoute basically justs returns a URL in the following format

index.php?option=com_content&view=category&id=[ID PARAMETER]&lang=[LANGUAGE PAREMETER]

It's not a particularly complicated function - the entirity is as follows:

if ($catid instanceof JCategoryNode)
        {
            $id = $catid->id;
        }
        else
        {
            $id = (int) $catid;
        }
        if ($id < 1)
        {
            $link = '';
        }
        else
        {
            $link = 'index.php?option=com_content&view=category&id=' . $id;
            if ($language && $language !== '*' && JLanguageMultilang::isEnabled())
            {
                $link .= '&lang=' . $language;
            }
        }

This has nothing really to do with JRoute, to which you can pass any paramaterised URL you want to run through a router to get a clean URL. getCategoryRoute simply returns a parameterisd URL that works with com_content's category view.

It's not clear what you mean by "the same functionality", as com_content's featured view does not work in the same way as the category view. With the featured view, categories are assigned as part of the menu item, and saved in the database as a menu item parameter, as opposed to being sent via URL parameters.

If you just want to create a link to the featured view using JRoute then the following should work (this will be all categories, though):

JRoute::_("index.php?option=com_content&view=featured&lang=[language]");

If the featured item is a menu item (with categories optionally assigned), then the following would also work:

JRoute::_("index.php?Itemid=MENUID");
Richard B
Richard B
June 07, 2017 13:13 PM

Related Questions



New Joomla Router: Adding additional item type views

Updated August 05, 2018 06:10 AM

Unset not removing parameter from URL

Updated December 06, 2016 08:04 AM


Generating URL in CLI

Updated April 13, 2018 11:10 AM