1

I have a problem with joomla 1.5 friendly url (that not so friendly actually) I am not using SEF at the moment (should i ?)

heres is my problem

I have some categories and sections. Each has alias.

so i can check all news category for example by visiting www.myxyz.com/news/

to check an article the url that generated would become: www.myxyz.com/news/10-local-news-title-alias

I have no idea how joomla generate that url. In my templates i need to generate some links to specific articles.

so I create a helper in template:


// helper to get alias in mainMenu ... alias must be unique 
function getMainMenu($menuAlias){
    $items = &JSite::getMenu();
    // Get Menu Items
    $rows = $items->getItems('alias', $menuAlias);
    if($rows){
        //$result = JRoute::_(JURI::base().$rows[0]->link);
        $result= JURI::base().substr(JRoute::_($rows[0]->link), strlen(JURI::base(true)) + 1);
        return $result;
    }else{
        return JURI::base() ;// aka not found
    }
}

but when I enter the page like www.myabc.com/news/7-local-news-alias the url would become messed up and changed to wrong url.

should I use SEF for joomla url friendly ?

nightingale2k1
  • 10,095
  • 15
  • 70
  • 96

2 Answers2

2

You should just work with normal url's in your code. when you turn on SEF joomla! will automaticly convert all links you create to SEF urls and when a request comes in it will revert them back to regular url's for you...

NDM
  • 6,731
  • 3
  • 39
  • 52
2

It's a little convoluted, but the proper way to link to SEF URLs is to use the original, non-SEF link. You will need:

  • The ID of the article
  • The Itemid of the menu item for your section (e.g. the menu item linking to Article Blog layout, etc)

Then you just link to:

index.php?option=com_content&view=article&id=42&Itemid=3

Where 42 is the article ID and 3 is the menu ID.Your link will then look something like:

/section-alias/42-the-article-alias

If you miss off the Itemid your link will look like this (I think):

/components/content/42-the-article-alias
DisgruntledGoat
  • 70,219
  • 68
  • 205
  • 290