Generate PHP dynamic menu and submenu

0

I need to generate a dynamic menu based on certain permissions. My structure looks like this: I have three tables:

-------------+-------------+------------
[Menu]       |  [Usuario]  | [permissao]
idmenu       |  iduser     | idper
nivelmenu    |  username   | iduser
descricao    |  senha      | idmenu
                           | pemite (0,1)

I query in permissao to check if it allows = 1, if yes, I need to store the nivelmenu (if it is normal menu = 1, 2, 3, ... else 1.1, 1.2, ...).

$sql = "SELECT p.idper, u.username, m.nivelmenu, m.descricao, p.permite FROM permissao p"
                . " INNER JOIN usuario u ON p.iduser = u.iduser"
                . " INNER JOIN menu m ON m.idmenu = p.idmenu"
                . " WHERE p.iduser = :iduser AND p.permite = 1";

        $cnx = conexao::getInstance()->prepare($sql);
        $cnx->bindValue(':iduser', $user->getIduser());

        $cnx->execute();

        if ($cnx->rowCount() > 0) {
            $menus = $cnx->fetch(PDO::FETCH_ASSOC);

            $imenu[] = 0;
            $isubmenu[] = 0;

            $nivel = $menus['nivelmenu'];

            foreach ($menus as $menu) {
                if ($nivel != strstr($nivel, '.', TRUE)) {
                    $imenu[] += $menu;
                }
                foreach ($menus as $menu) {
                    if ($nivel == strstr($nivel, '.', TRUE)) {
                        $isubmenu[] += $menu;
                    }
                }
            }

I have been able to do this code so far, but it is giving error:

  

Warning: A non-numeric value encountered   for this code: $imenu[] += $menu; .

I can not resolve to generate these menus. I need you to run a menu like this:

HOME | Cadastros | Etc (aqui é se o nivel menu for inteiro (1, 2, 3 ..)
     > Clientes (Aqui é se for (1.1, 1.2 ...)
    
asked by anonymous 08.11.2018 / 20:28

0 answers