0
I have a result that comes after a query in the database. With this result I make the menu dynamically, when the user has permission to view the page. What I would like to know is if you have the option of improving my code, it is working, but I would like to improve it if possible and have less line to compile. This if is only the first, to complete the entire menu have to repeat it 50 times, which are the menu items. I tried to use the "switch", but also without success.
Here I receive the data from the database query
$paginas = $pagina->verificaPaginas();
$qtdRow = count($paginas);
Result of $pages
array(168) { [0]=> array(9) { ["idpagina"]=> string(1) "1" ["url"]=> string(34) "../Acervos/acervoViewCad.class.php" ["descricao"]=> string(9) "CADASTRAR" ["categoria"]=> string(1) "1" ["grupo"]=> string(1) "1" ["acessoid"]=> string(1) "1" ["idlogin"]=> string(1) "1" ["paginaid"]=> string(1) "1" ["visualizar"]=> string(1) "1" } [1]=> array(9) { ["idpagina"]=> string(1) "2" ["url"]=> string(37) "../Acervos/acervoViewEditar.class.php" ["descricao"]=> string(7) "ALTERAR" ["categoria"]=> string(1) "1" ["grupo"]=> string(1) "1" ["acessoid"]=> string(1) "2" ["idlogin"]=> string(1) "1" ["paginaid"]=> string(1) "2" ["visualizar"]=> string(1) "1" } [2]=> array(9) { ["idpagina"]=> string(1) "3" ["url"]=> string(40) "../Categorias/categoriaViewCad.class.php" ["descricao"]=> string(9) "CADASTRAR" ["categoria"]=> string(1) "2" ["grupo"]=> string(1) "1" ["acessoid"]=> string(1) "3" ["idlogin"]=> string(1) "1" ["paginaid"]=> string(1) "3" ["visualizar"]=> string(1) "1" } [3]=> array(9) { ["idpagina"]=> string(1) "4" ["url"]=> string(43) "../Categorias/categoriaViewEditar.class.php" ["descricao"]=> string(7) "ALTERAR" ["categoria"]=> string(1) "2" ["grupo"]=> string(1) "1" ["acessoid"]=> string(1) "4" ["idlogin"]=> string(1) "1" ["paginaid"]=> string(1) "4" ["visualizar"]=> string(1) "1" } [4]=> array(9) { ["idpagina"]=> string(1) "5" ["url"]=> string(43) "../Fornecedores/fornecedorViewCad.class.php" ["descricao"]=> string(9) "CADASTRAR" ["categoria"]=> string(1) "3" ["grupo"]=> string(1) "1" ["acessoid"]=> string(1) "5" ["idlogin"]=> string(1) "1" ["paginaid"]=> string(1) "5" ["visualizar"]=> string(1) "1" } [5]=> array(9) { ["idpagina"]=> string(1) "6" ["url"]=> string(64) "../Fornecedores/insereMatriculaEditaFornecedorViewGrid.class.php" ["descricao"]=> string(12) "ALTERAR POST" ["categoria"]=> string(1) "3" ["grupo"]=> string(1) "1" ["acessoid"]=> string(1) "6" ["idlogin"]=> string(1) "1" ["paginaid"]=> string(1) "6" ["visualizar"]=> string(1) "1" }
This is where I build the menu dynamically
<nav id="menu">
<ul class="menu"> <!-- Esse é o 1 nivel ou o nivel principal -->
<?php for ($a = '0';
$a < $qtdRow;
$a++) { ?>
<!-- Inicio menu cadastros -->
<?php if (($paginas[$a]['grupo'] == 1)) { ?>
<li><a href="#">CADASTROS</a>
<ul class="submenu-1"> <!-- Esse é o 1 nivel ou o primeiro Drop Down -->
<?php for ($a = '0';
$a < $qtdRow;
$a++) { ?>
<?php if (($paginas[$a]['categoria'] == 1)) { ?>
<li><a href="#">ACERVO</a>
<ul class="submenu-2"> <!-- Esse é o 2 nivel ou o primeiro Drop Down -->
<?php for ($a = '0'; $a < $qtdRow; $a++) { ?>
<?php if (($paginas[$a]['categoria'] == 1) && ($paginas[$a]['grupo'] == 1)) { ?>
<li><a href="javascript:void(0)"
onclick='window.open("<?= $paginas[$a]['url']; ?>", "iframe_a")'><?= $paginas[$a]['descricao']; ?></a>
</li>
<?php } ?>
<?php } ?>
</li>
</ul>
<?php } ?>
<?php } ?>
</li>
</li>
</ul>
<?php } ?>
<!-- Fim menu cadastro-->
<?php } ?><!-- Fecha contagem -->
Even with WHILE or SWITCH, the same thing happens.
– Fernando Trilha
These terms CADASRS and ACQUIS, for example, does not come from the bank? Post the code of
$paginas = $pagina->verificaPaginas();
, may help in formulating an idea. Perhaps follow the idea of setting up a function for each level and action.– Gnomo Escalate
Good morning @Gnomoescalate, not these terms do not come from the bank, which comes from the bank is the number that in this case represents the group and the category. You want the result of $pages = $page->checkWebsite();.
– Fernando Trilha
I added part of the result @Gnomoescalate.
– Fernando Trilha
I got it, I got it. What you take is that the terms REGISTRATION and COLLECTION, for example, are entered into your code manually, to facilitate the creation of a function they would need to be in a database, array associated with the group or category.
– Gnomo Escalate
Only that not only I have the ACQUIS, I have several others that compose the menu.
– Fernando Trilha