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

时间:2015-07-23 09:55:09

标签: joomla

我创建了一个Joomla 3组件,它将以编程方式添加一些菜单项。我已经搜索了如何做到这一点,我找到了这个老问题/答案: Programatically Create Menu Item in Joomla

使用此代码

            //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 ......

有人提出这个我无法理解的解决方案。

  

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

     

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

     

//重建树路径。   if(!$ table-> rebuildPath($ table-> id)){       $这 - > SETERROR($表 - > getError());       返回false;   }

有人可以解释我在哪里使用该解决方案吗?

0 个答案:

没有答案