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?


The lft and rft code is quite old in Joomla, and only used in a sub-set of core functionality. Basically it means...

  • lft: the item id of the item to the left
  • rgt: the item id of the item to the right

If you add items to the table, you'll maybe find you need to "rebuild" the menu. This is a button at the top of the menu manager that basically sets all the lft and rft values.

If you're adding menu items programmatically, to the database, you may need to "rebuild" them afterwards.

Further reading


Simply - it's for ordering in subsets. If need real info about it - see Wiki "Nested Sets"

Concerning Joomla and adding menu items via custom PHP - it's simple if you use what provided here https://docs.joomla.org/Using_nested_sets

Concerning of what you should to keep in mind - #__assets table also uses Nested Sets

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.