0

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

Edit Screenshot enter image description here

  • If this a fresh installation of Joomla? Are you using any 3rd party templates or extensions? – Lodder Aug 14 '16 at 10:15
  • Have you tried going into both the menu manager and category manager and hitting the "rebuild" button? – YellowWebMonkey Aug 14 '16 at 19:27
  • @Lodder - yes using 3rd party template and extensions. – Ruchika Aug 15 '16 at 16:23
  • Do any of the extensions you're using manipulate the menus in any way? Or does your template override the menu in some way? Without knowing this sort of information, it's pretty hard to tell where the issue resides. – Lodder Aug 15 '16 at 16:25
  • @Lodder - i really do not know, they are custom build templates and developer not available – Ruchika Aug 15 '16 at 16:26
1
+50

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.

  • @Yellowwebmoneky - Its already there with the details, see attached screenshot in question – Ruchika Aug 18 '16 at 15:29
  • I apologize if I missed something. When did you edit the answer? Are you saying that is the solution that fixed it, or that you tried it and you are still having the issue? – YellowWebMonkey Aug 18 '16 at 19:44
  • Hello, The menu root item still exists as mentioned but the issue remains – Ruchika Aug 19 '16 at 2:02
  • I would give ACL Manager a shot. It is a paid extension but is worth it and has fixed similar issues for me: aclmanager.net – YellowWebMonkey Aug 19 '16 at 2:43
  • As per recommendation - bought the extension - but it dint helped either. the error notice still remains – Ruchika Aug 22 '16 at 7:01
1

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

enter image description here

  • Hello, Setting server to none is like hiding the error, i can do it even by changing core to $levelPrefix = str_repeat('- ', $link->level); . But, without changing core been the error happening after fix db or rebuild menu - unsure why is it happening – Ruchika Aug 18 '16 at 5:31
  • @Ruchika.. Well - error reporting must in any case set to none on a production site. And that's exactly what error reporting = none is designed to do. To hide any notices, warnings and even errors from being displayed. Like Adam said, if everything functions fine, you can safely set error_reporting to none (for now). Warnings are warnings for a possible issue. Although it's good to have none, you wouldn't be able to fix all possible ones of a php application, especially if you don't fully control it (the app). – FFrewin Aug 18 '16 at 8:10
  • @FFrewin - thanks, yes it looks like that the functionality of site is okay - but is there a override which can be developed as php notice on brand new joomla site indicate something is wrong. – Ruchika Aug 18 '16 at 10:47
  • @Ruchika see my answers update. Hope it solves the problem. – Adam M. Aug 19 '16 at 9:54
  • Thanks for the heads up - checked all levels are correct, root is 0, new menu are 1 and sub menu are 2. However all submenu are unpublished as we are not using submenu. We are only using main menus – Ruchika Aug 19 '16 at 16:19
0

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.

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.