$table->setLocation($parent_id, 'last-child');
- this is all that is necessary to ensure the correct creation of left / right values ββfor a new menu item. There is no need to rebuild the path, as it is now being processed by the JTableMenu storage method.
In addition, the "save" method of a convenient method can be used to bind, check, and save a menu item:
$menuItem = 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' => $parent_id, 'level' => 1, ); $menuTable = JTable::getInstance('Menu', 'JTable', array()); $menuTable->setLocation($parent_id, 'last-child'); if (!$menuTable->save($menuItem)) { throw new Exception($menuTable->getError()); return false; }
source share