drzip28288 2014-02-17 10:09
浏览 91
已采纳

注意:未定义的索引:index.php

I' am getting `

Notice: Undefined index: index.php in xxxxx/index.php on line 26

When I remove the $submenu variable array from menu.php. Everything works fine but when I add $submenu array variable I get error message. ` What I' am trying to do here is get the top level first and then search if theirs any child submneu

On index.php file I have this code

    foreach($menu as $menu){
            $title = $menu[0];
            $privllages = $menu[1];
            $template = $menu[2];
            $class = $menu[3];
            $id = $menu[4];
            $icon = $menu[5];

            if(!$title){$title = 'No Title';}
            if($class){$class = 'class="'.$class.'"';} else {$class = '';}
            if($id){$id = 'id="'.$id.'"';} else {$id = '';}
            if(!$icon){$icon = "menu-default.png";}

            echo '<a href="'.$template.'" '.$class.' '.$id.'>' . $title . '</a>' . "<br/>";

/* LINE 26 Starts here */ 
                if($submenu[$template]){
                    foreach($submenu[$template] as $submenu){
                        echo '<a href="#">' . $submenu[0] . '</a>' . "<br/>";
                    }
                }
        }

On menu.php file

$menu[1] = array('Dashboard', '0', 'index.php', 'sidebar-menu','','menu-dashboard');
$menu[2] = array('Pages', '0', 'pages.php', 'sidebar-menu','','menu-dashboard');
$menu[3] = array('Media', '0', 'media.php', 'sidebar-menu','','menu-dashboard');
$menu[4] = array('Tools', '0', 'tools.php', 'sidebar-menu','','menu-dashboard');
$menu[5] = array('Users', '0', 'users.php', 'sidebar-menu','','menu-dashboard');
$menu[6] = array('Settings', '0', 'settings.php', 'sidebar-menu','','menu-dashboard');

$submenu['pages.php'][1] = array( 'All Links 1', 'admin-menu', 'manage_links', 'link-manager.php' );
$submenu['pages.php'][2] = array( 'All Links 2', 'admin-menu', 'manage_links', 'link-manager.php' );
$submenu['pages.php'][3] = array( 'All Links 3', 'admin-menu', 'manage_links', 'link-manager.php' );
$submenu['pages.php'][4] = array( 'All Links 4', 'admin-menu', 'manage_links', 'link-manager.php' );
  • 写回答

3条回答 默认 最新

  • dongnianwo8289 2014-02-17 10:14
    关注

    Instead of

    if($submenu[$template]){
    

    use

    if(!empty($submenu[$template])){
    

    This will then only trigger if $submenu[$template] exists and is not empty

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历