如何从Joomla中的自定义前端组件调用菜单重建


How to invoke Menu rebuild from the custom front-end component in Joomla?

我正在使用Joomla 2.5创建一个从前端执行的特殊组件。

该组件解析xml文件以构建Joomla菜单,我正在执行INSERT INTO#__menu查询,但我为lftrgt

菜单构建得非常混乱,当我单击后端的Rebuild按钮时,一切看起来都很完美,pathlftrgt

我花了两天时间尝试从前端组件的控制器和模块执行重建任务,我甚至尝试使用jimport('joomla.database.tablenested'),但我缺乏PHP OOP知识,无法正确执行rebuild函数。。。

我写的最后一件事是:

jimport('joomla.database.tablenested');
class BSImportModelBSImport extends JModel
{
  ...
  function theimport()
  {
    ...
    $db =& JFactory::getDBO();
    $menu = new JTableNested('Menu', 'id',&$db);
    return $menu->rebuild();
  }
}

如果我的问题看起来很愚蠢,请不要往我头上扔石头。。。我真的需要帮助。。。

我使用菜单表的保存方法:

$data = array ( 
    'id' => 0 ,
    'title' => '{menu name}' ,
    'note' => '',
    'link' => '{link}',
    'menutype' => '{menutype}' ,
    'type' => 'url', 
    'published' => 1 ,
    'parent_id' => 1 ,
    'level' => 1 ,
    'component_id' => 0 ,
    'browserNav' => 0 ,
    'access' => getLevel() ,
    'template_style_id' => 0 ,
    'language' => '*' ,
    'params' => array ( 
        'menu-anchor_title' => '' ,
        'menu-anchor_css' => '' ,
        'menu_image' => '{url of logo for menu}',
        'menu_text' => 1 ) ,
);
$menuTable = JTable::getInstance('Menu', 'JTable', array());
$menuTable->save($data);

此方法创建新菜单并自动重新生成。