Reputation: 3870
I was trying to manually add menu item to the database. See this question, when I notice these two fields in the #__menu
table. It seems to me they are auto increasing by 2. For example, if the latest menu item have {lft:121,rgt:122}, then a new menu item will have {lft:123,rgt,124}. A brief searching shows they are related to something called "nested model", and I look at other Joomla tables, many have these two fields too.
Not understanding what they are, I just add new record to the table, and I gave each new record these two fields, keeping the auto increment.
Today I tried to add a new menu item through back-end and get this error message:
Save failed with the following error: exception 'UnexpectedValueException' with message 'MenusTableMenu::_getNode(1, ) failed.' in /home/p/public_html/libraries/joomla/table/nested.php:1532 Stack trace: #0 /home/p/public_html/libraries/joomla/table/nested.php(773): JTableNested->_getNode(1) #1 /home/p/public_html/libraries/legacy/table/menu.php(243): JTableNested->store(false) #2 /home/p/public_html/administrator/components/com_menus/models/item.php(1258): JTableMenu->store() #3 /home/p/public_html/administrator/components/com_menus/controllers/item.php(267): MenusModelItem->save(Array) #4 /home/p/public_html/libraries/legacy/controller/legacy.php(728): MenusControllerItem->save() #5 /home/p/public_html/administrator/components/com_menus/menus.php(18): JControllerLegacy->execute('apply') #6 /home/p/public_html/libraries/cms/component/helper.php(405): require_once('/home/p/public_...') #7 /home/p/public_html/libraries/cms/component/helper.php(380): JComponentHelper::executeComponent('/home/p/public_...') #8 /home/p/public_html/libraries/cms/application/administrator.php(98): JComponentHelper::renderComponent('com_menus') #9 /home/p/public_html/libraries/cms/application/administrator.php(152): JApplicationAdministrator->dispatch() #10 /home/p/public_html/libraries/cms/application/cms.php(257): JApplicationAdministrator->doExecute() #11 /home/p/public_html/administrator/index.php(51): JApplicationCms->execute() #12 {main}
I see nested
is involved in this issue, so I guess it has something to do with the two fields that I ignored. How to fix this?
P.S., I hardcoded some PHP to add record into the #__menu
, I think this also play a part in the problem. Too add menu item, besides #__menu
, is there any other table I need to take care of?
Upvotes: 0
Views: 223
Reputation: 6755
Menus are constructed using nested sets which allows for many highly useful features, including coherent URL naming, moving sub-trees around, certain aspects of multilanguage handling, and other items. As you learned you cannot just insert a row. That does not mean you have to do it one item at a time using the administrative interface. You have many options to do it more easily depending on if you want to write a simple CLI application to create new items or if you would rather do it in more of a gui-based manner by, for example, copying a sub-tree structure so that the nesting works correctly and then you can edit the text in the data base.
Upvotes: 0