0

Why does JRoute include parts that weren't set in the output SEF Url ?

Example: I have a view that lists Items, every item links to another view (Item) with an ID. When I put all parts of the query string together I get both views on the URL:

domain.com/index.php/component/ items/ item/1-alias

instead of

domain.com/index.php/component/item/1-alias

because I use different views for all the parts of the component and not layouts.

Both URLs work just fine, but why does it do that? I don't want it to build the SEF URL with the original view of Items, just the view for single items. It wouldn't be a problem if the Item view wasn't getting the menu param of the Items view.

Edit:

This is how I use the JRoute::_() method.

JRoute::_( 'index.php?option=com_componentname&view=show&show_id='.$item->slug);

And the contents of the router.php script

jimport('joomla.database.databasequery');

function ComponentnameBuildRoute(&$query) {

    $segments = array();

    if(isset($query['view'])) {
        $view = $query['view'];
        $segments[] = $view;
        unset($query['view']);
    }

    if(isset($query['task'])) {
        $view = $query['task'];
        $segments[] = $view;
        unset($query['task']);
    }

    if(isset($query['show_id'])) {
        $view = $query['show_id'];
        $segments[] = $view;
        unset($query['show_id']);
    }

    if(isset($query['genre_id'])) {
        $view = $query['genre_id'];
        $segments[] = $view;
        unset($query['genre_id']);
    }

    if(isset($query['rated_id'])) {
        $view = $query['rated_id'];
        $segments[] = $view;
        unset($query['rated_id']);
    }

    return $segments;
}

function ComponentnameParseRoute($segments) {

    $vars = array();

    switch($segments[0]) {

        case 'show':
            $vars['view'] = $segments[0];
            $id = explode('-', $segments[1]);
            $vars['show_id'] = (int)$id[0];
            break;
        case 'genre':
            $vars['view'] = $segments[0];
            $vars['genre_id'] = (int)$segments[1];
            break;
        case 'rating':
            $vars['view'] = $segments[0];
            $vars['rated_id'] = (int)$segments[1];
            break;
        case 'shows':
            $vars['view'] = $segments[0];
            break;
        case 'genres':
            $vars['view'] = $segments[0];
            break;
        case 'ratings':
            $vars['view'] = $segments[0];
            break;
    }

    return($vars);
}
droplet
  • 286
  • 4
  • 13

0 Answers0