0

Can someone please tell me how to add a segment to the beginning of the SEF URL - i.e:

http://somedomain.com/*SEGMENT*/task/id

The *SEGMENT* is just a static string, just for show and is not taken from the query.

I've got a very basic router.php in my component:

function MyComponentBuildRoute(&$query)
{
    $segments = array();

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

    return $segments;
}

function MyComponentParseRoute($segments)
{
    $vars = array();
    $count = count($segments);

    if ($count) {
        $count--;
        $segment = array_shift($segments);
        if (is_numeric($segment)) {
            $vars['id'] = $segment;
        } else {
            $vars['task'] = $segment;
        }
    }

    if ($count) {
        $count--;
        $segment = array_shift($segments) ;
        if (is_numeric($segment)) {
            $vars['id'] = $segment;
        }
    }
return $vars;
}

Hope someone can help!

Shaz
  • 2,647
  • 2
  • 35
  • 45
mousebat
  • 474
  • 7
  • 25

1 Answers1

0

Create a menu item for the view in the component. If you SEGMENT needs to be /foo/, then just make sure the alias of the menu item is "foo". If you need a slash, i.e. /foo/bar/, you would need to nest two menu items with the aliases "foo" and "bar". This will tell Joomla how to handle it.

Riccardo Zorn
  • 5,590
  • 1
  • 20
  • 36