I'm writing a module that 开发者_JS百科has articles. I would like these article to end with the "read more" button. This button should redirect to a menuitem pointing to the full article if such a menuitem exists, or to the article (as in component=com_content&id=... etc.) if this is not the case.
Right now I'm using JRoute with the id:
$url = JRoute::_( 'index.php?option=com_content&view=article&id='.$article->id );
but this returns the following url:
$url = "http://example.com/option=com_content&view=article&id=1"
This points to the correct article, but is not search-engine friendly (it is on, with .htaccess support) AND it leads to a different page than my menuitem pointing to the article.
I'm sure it has to do something with JRoute but I can't find any resource on how to make this work.
Any ideas? Thanks!
Try using the ComponentHelperRoute:
$link = JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article->catslug, $article->sectionid));
精彩评论