以编程方式更新joomla中的Component中的Menu Item

时间:2017-02-15 19:05:59

标签: php joomla

我在Joomla中创建一个组件,除此之外,还可以创建和更新菜单,我已成功使用此答案创建一个新的菜单项。 https://joomla.stackexchange.com/questions/5104/programmatically-add-menu-item-in-component?newreg=1e7c576205354c0795a55607bc3e2508

$menuTable = JTableNested::getInstance('Menu');

// which menu you want to add to - 
$menutype = 'thisismymenusname';

// this is heading menu item but what data you have and require will vary per case - just look at an appropriate row in yr menu table
$menuData = array(
'menutype' => $menutype,
  'title' => $table->alias,
  'alias' => $table->alias,
  'path' => $table->alias,
  'type' => 'heading',
  'component_id' => 0,                  
  'language' => '*',
   'published' => 1,
);

// this item is at the root so the parent id needs to be 1
$parent_id = 1;
$menuTable->setLocation($parent_id, 'last-child');

// save is the shortcut method for bind, check and store
if (!$menuTable->save($menuData))
{
  $this->setError($menuTable->getError());
  return false;
}

但我无法找到更新菜单项的正确方法,例如标题和别名。但它没有成功。我试过使用它没有成功。

            $menu_title = $_POST['title'];
            $menu_alias = JFilterOutput::stringURLSafe($menu_title);

            $menuTable = JTableNested::getInstance('Menu');

            // this is heading menu item but what data you have and require will vary per case - just look at an appropriate row in yr menu table
            $menuData = array(
                'title' => $menu_title,
                'alias' => $menu_alias,
            );

            // this item is at the root so the parent id needs to be 1
            $parent_id = ($_POST['parent'] != "" ? $_POST['parent'] : '1');
            $menuTable->setLocation($parent_id, 'last-child');

            // save is the shortcut method for bind, check and store
            if (!$menuTable->set($_POST['menuid'],$menuData)) {
                $this->setError($menuTable->getError());
                exit;
            }

有人可以帮忙吗?

0 个答案:

没有答案