以编程方式在joomla中创建菜单项

以编程方式在joomla中创建菜单项,joomla,Joomla,我已经创建了一个Joomla3组件,它将以编程方式添加一些菜单项。我搜索了如何做,发现了这个老问题/答案: 建议使用以下代码: //add the article to a menu item $menuTable = JTable::getInstance('Menu', 'JTable', array()); $menuData = array( 'menutype' => 'client-pages', 'title' => $data[name],

我已经创建了一个Joomla3组件,它将以编程方式添加一些菜单项。我搜索了如何做,发现了这个老问题/答案:

建议使用以下代码:

//add the article to a menu item
$menuTable = JTable::getInstance('Menu', 'JTable', array());

    $menuData = array(
    'menutype' => 'client-pages',
    'title' => $data[name],
    'type' => 'component',
    'component_id' => 22,                  
    'link' => 'index.php?option=com_content&view=article&id='.$resultID,
    'language' => '*',
    'published' => 1,
    'parent_id' => '1',
    'level' => 1,
);

// Bind data
if (!$menuTable->bind($menuData))
{
    $this->setError($menuTable->getError());
    return false;
}

// Check the data.
if (!$menuTable->check())
{
    $this->setError($menuTable->getError());
    return false;
}

// Store the data.
if (!$menuTable->store())
{
    $this->setError($menuTable->getError());
    return false;
}
它是有效的,但问题与我链接的问题相同。 显示错误:警告:str_repeat()[function.str repeat]:第二个参数必须大于或等于0 in

有人提出这个解决方案,我不明白

尝试使用JTableNested::setLocation($referenceId,$position='after'):

$table->setLocation($parent_id,'last child'); 我还认为您需要重建路径:

//重建树路径。 如果(!$table->重建路径($table->id)){ $this->setError($table->getError()); 返回false; }

有人能告诉我在哪里使用这个解决方案吗