Set up a new site in Joomla 3.6
My Joomla menu module always shows this error
Warning: str_repeat(): Second argument has to be greater than or equal to 0 in public_html/libraries/cms/form/field/menuitem.php on line 220
How to solve same
Joomla Stack Exchange is a question and answer site for Joomla! administrators, users, developers and designers. It only takes a minute to sign up.
Sign up to join this communitySet up a new site in Joomla 3.6
My Joomla menu module always shows this error
Warning: str_repeat(): Second argument has to be greater than or equal to 0 in public_html/libraries/cms/form/field/menuitem.php on line 220
How to solve same
If you are comfortable working with the database, go to phpMyAdmin and browse the #__menu table. Sort by ID and make sure you have a record that is:
ID: 1
Title: Menu_Item_Root
Alias: root
Published: 1
and everything else can be left blank to fill in defaults.
It's hard to say where is the problem, but it seems to be a problem with your 3rd party templates or extensions. You get the problem on this line
$levelPrefix = str_repeat('- ', $link->level - 1);
From this file https://github.com/joomla/joomla-cms/blob/staging/libraries/cms/form/field/menuitem.php
It handles adding hyphens - to menu items, ex.:
menu
--second-level
---third-level
I saw you have already tried to rebuild the menu, don't know which level, but better rebuild them all, remove and build new. But, first fix any DB errors (Extensions->Manage->Database).
Anyway, even with this warning, everything should work as expected, maybe you just won't see some hyphens (-) in the backend. If it's not a problem, then you can disable this type of warning, just go to System->Global Configuration->Server
and set error reporting to none.
Edit
Saw your screenshot. Since it regards "levels" then you can check if you have right levels inside #__menu
table.
Menu_Item_Root row should have column level
set to 0, all new menus should be set to 1 and deeper submenus should be 2, and so on. If you create a new menu and you will see it's level set to anything else then 0, then this causes the warning and we will need to see why it saves the menu with lower, higher level.
Menu_Item_Root
should look like this
This looks like a bug in Joomla to me. The problem is that the very first entry in the menu table is the mainmenu with the value of the level colum set to 0. When you hit the line
$levelPrefix = str_repeat('- ', $link->level - 1);
at line 220 of menuitem.php, $link->level is 0 for tne mainmenu. This creates the error message.
One way to fix this would be to change the line to read:
$levelPrefix = str_repeat('- ', max($link->level - 1, 0));
Of course, this should really be done in the Joomla source code.