0

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?

Community
  • 1
  • 1
shenkwen
  • 3,536
  • 5
  • 45
  • 85
  • 1
    Never really worked with joomla but lft and rgt are not auto increasing, so you broke the menus hierarchy by manually inserting stuff into database. Lft and rgt are used for quickly traversing a tree structure or in this case to determine which submenu belongs to which parent menu etc. When you insert a new submenu into database lft and rgt of every menu have to be corrected. Why not just create menus through admin panel? – TheDrot May 13 '16 at 23:34
  • I have many k2 items that I need to create menu item for each one of them, doing this through admin panel is too frustrating – shenkwen May 13 '16 at 23:36
  • Thanks. At least I confirm that I've broken it. Thank God I made a full backup before I did that. – shenkwen May 13 '16 at 23:37
  • Trust me manually inserting/updating into nested models is even more frustrating. – TheDrot May 13 '16 at 23:37
  • That is something I want to understand. What is nested model and what could it possibly have to do with Joomla's menu item? I will change my question title to this one. – shenkwen May 13 '16 at 23:38
  • http://stackoverflow.com/questions/5368299/hierarchical-data-nested-set-model-mysql This should help you. – TheDrot May 13 '16 at 23:42

1 Answers1

0

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.

Elin
  • 6,507
  • 3
  • 25
  • 47