views:

83

answers:

1

Hi,

I have a simple menu hierachy in a Joomla 1.5 site:

[Newsletters] -> [publisher A] -> [Newsletter A1]
                               -> [Newsletter A2]
              -> [publisher B] -> [Newsletter B1]
                               -> [Newsletter B2]

When navigating this hierarchy using the menu items or breadcrumbs, the SEF URL's are as expected;

/newsletters/pubA.html
/newsletters/pubA/letterA1.html
/newsletters/pubA/letterA2.html
/newsletters/pubB.html
/newsletters/pubB/letterAB.html
/newsletters/pubB/letterAB.html

However, when navigating the hierarchy using links inside the pages, the url's get messed up. Read on for more details :)

The pages are generated by a component. I've implemented a JRouter to generate SEF URL's. With SEF turned on, I can correctly navigate the hierachy using menu items and the standard breadcrumbs.

However, I also want to navigate by links on the pages themselves (for example, by linking to all of a publisher's newsletters on the publisher's page, or by linking back to the publisher's page from a newsletter's page). This works fine when going from publisher to newsletter. The component calls

JRoute::_('index.php?option=' . $option . '&view=newsletter&newsletterid=' . $newsletterId );

and (correctly) generates a URL like:

/newsletters/pubA/letterA1.html

However, when a user is on a newsletter page and wants to go back up to the publisher's page, things go wrong. For some reason the publisher's alias gets added after the newsletter's alias in the URL, as if it was below the newsletter in the hierachy. The component calls

JRoute::_('index.php?option=' . $option . '&view=publisher&publisherid=' . $publisherId );

but that (incorrectly) generates a URL like:

/newsletters/pubA/letterA1/pubA.html

If I navigate forward to a newsletter again from the above URL, then the URL becomes

/newsletters/pubA/letterA1/letterA1.html
/newsletters/pubA/letterA1/pubA.html
/newsletters/pubA/letterA1/letterA1.html
/newsletters/pubA/letterA1/pubA.html

(i.e., it doesn't go deeper than one or two segment(s) 'wrong'.)

Also, please note that navigation does work (meaning, the right page is opened) -- it's just the URL that looks weird.

I don't see how I could generate the expected URL's as shown at the top; there doesn't seem to be a way to specify 'relative to what' the 'first' segment should be. Should I be tapping into JSite::getRouter() somehow?

The router code is pretty straight forward. It's the first time I write a router, so I could have messed up something. I do find it suspicious that ParseRoute is only ever called with a single segment.

function ComponentBuildRoute(&$query)
{
  $segments = array();
  if (isset($query['view']))
  {
     if (isset($query['newsletterid']))
     {
        $alias = { figure out newsletter alias from newsletter id }
        $segments[] = $alias;
        unset($query['newsletterid']);
     }      
     else if (isset($query['publisherid']))
     {
        $alias = { figure out publisher alias from publisher id }
        $segments[] = $alias;
        unset($query['publisherid']);         
     }

    unset($query['view']);
  }

  return $segments;
}

function ComponentParseRoute($segments)
{
   $vars = array();

   $id = { try to retrieve newsletter id matching alias in $segments[0] }
   if (!empty($id))
   {
     $vars['view'] = 'newsletter';
     $vars['newsletterid'] = $id;    
     return $vars;
   }
   $id = { try to retrieve publisher id matching alias in $segments[0] }
   if (!empty($id))
   {
     $vars['view'] = 'publisher';
     $vars['publisherid'] = $id;    
     return $vars;
   }

   return $vars;
}

I don't want to use an absolute URL because the publisher's menu item sits under the newsletters menu... obviously there must be a way of doing this as both the menu items and the breadcrumb modules figured it out...

Thanks

A: 

There is a problem with your ComponentBuildRoute. In the else if block where you deal with publisherid you unset newsletterid. I am not sure if that is the problem, but fixing it would be the first step to get this issue resolved.

silvo
Thanks -- that was just a typo when writing the code for in here (which I've now fixed). The actual code correctly unset publisherid
Jimmy