I'm trying to create an menu with submenus
.
I created two tables on my database, here the data:
Menu table -
menu_id
front
back
url
menu_friendlyname
name
modules active
Submenu table -
submenu_id
menu_id url
submenu_name
modules
I'm doing a specie of MVC, but with my own rules, here the model:
I'm calling two tables here
$query = ("SELECT DISTINCT name, menu_id
FROM menu
INNER JOIN submenu USING(menu_id)");
$array = db_array($query, 'a+');
if (!empty($array)) {
printMenu($array);
return true;
} else {
return false;
}
}
And I'm calling the view here, as you can see, I'm trying to show the submenus
function printMenu($array){
echo '<pre>';
var_dump($array);
echo '</pre>';
foreach($array as $key => $values){
echo '<ul>';
echo '<li>';
echo $values['name'];
echo '</li>';
echo '<li>';
foreach($values['submenu'] as $k => $v){
echo '<span>';
echo $v['submenu'];
echo '</span>';
}
echo '</li></ul>';
}
}
And is giving me this error:
Notice: Undefined index: submenu
Warning: Invalid argument supplied for foreach()
I did a var_dump too
array(5) {
[0]=>
array(2) {
["name"]=>
string(5) "admin"
["menu_id"]=>
string(1) "1"
}
[1]=>
array(2) {
["name"]=>
string(4) "user"
["menu_id"]=>
string(1) "2"
}
[2]=>
array(2) {
["
name"]=>
string(22) "permissions_management"
["menu_id"]=>
string(1) "3"
}
[3]=>
array
(2) {
["name"]=>
string(10) "job_offers"
["menu_id"]=>
string(1) "5"
}
[4]=>
array(2) {
["name"]=>
string(12) "applications"
["menu_id"]=>
string(1) "6"
}
}
Maybe the error is from the array
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…