到目前为止,我正在以最不舒服的方式重新发明轮子。我能在我的直觉中感觉到,这有一天会破裂并给我带来很多痛苦。因此,我正在寻找一种更好的方法来获取文章别名并构建菜单项 url 或文章 url。是否没有 joomla api 调用可以使这更容易/更清洁/更面向未来?
/* Find article by alias */
$db =& JFactory::getDBO();
$sql = 'select id from #__content where alias=' . "'$alias'";
$db->setQuery($sql);
$row = $db->loadAssoc();
$artId = $row['id'];
if ($artId != null) {
$artLink = 'index.php?option=com_content&view=article&id='.$artId;
/* Find menu item by article id */
$sql = 'select parent,alias from #__menu where link=' . "'$artLink'";
$db->setQuery($sql);
$row = $db->loadAssoc();
$menuLink = '';
while ($row != null) {
$menuLink = '/' . $row['alias'] . $menuLink;
$sql = 'select parent,alias from #__menu where id=' . $row['parent'];
$db->setQuery($sql);
$row = $db->loadAssoc();
}
$menuLink = 'index.php' . $menuLink;
}
$articleUrl = ($menuLink != '') ? 'index.php' . $menuLink : JRoute::_($artLink);