我不知道这是否是愚蠢的问题,对不起。但我是joomla的新手,我有一个问题,从给定的ID获取菜单标题。
is that possible ? if yes, how can i do it ?
答案 0 :(得分:1)
/** Getting the Menu ID of Menu was clicked by user **/
$menu = &JSite::getMenu();
$id = $menu->getActive()->id;
/** Getting the Title of the Menu by using id. **/
$db = JFactory::getDBO();
$query = "SELECT title FROM kjs_menu WHERE id = $id";
$db->setQuery($query);
$rows = $db->loadObjectList();
$itemrow = $rows[0];
$title = $itemrow->title;
echo "Menu you have clicked is : ".$title;
//或者这是一个可以指导你的简短方法:
$active = JFactory::getApplication()->getMenu()->getActive();
echo $active->title;
如果getActive能够获得活动菜单,则会返回一个对象,因此该对象还包含标题。 在进行任何输出之前,要确保有对象检查它。