Arrays 消息:未定义索引:子菜单

Arrays 消息:未定义索引:子菜单,arrays,indexing,Arrays,Indexing,嗨,我对codeigniter中的数组有一些问题,我如何将数组传递给视图,这里是代码不起作用 型号: public function get_all() { $query = $this->db->get('category'); $result = $query->result_array(); foreach( $result as $key =&g

嗨,我对codeigniter中的数组有一些问题,我如何将数组传递给视图,这里是代码不起作用

型号:

 public function get_all()
    {           

        $query = $this->db->get('category');
        $result = $query->result_array();                      
        foreach( $result as $key => $row )
        {

          $query = $this->db->get_where('categorysub',   array('categoryID'=>$row['categoryID']));

            $row['childmenus'] = $query->result_array();
            $result[$key] = $row;

        }            
        return $result;            
    }
控制器:

$this->load->model(array('mcategory','mcategorysub'));
    $data['title']= 'Detail Kategori';
    $data[] = array(
            'nestedmenu' => $this->mcategory->get_all());

    $data['nestedmenu'] = array($data);
    $this->load->view($this->template, $data);
视图:

   foreach($nestedmenu as $nestedmenu_type)
{

    echo "<h2>" . $nestedmenu_type['name'] . "</h2>";
    echo "<ul>";        
    foreach($nestedmenu_type['childmenus'] as $childmenu)
    {        
        echo "<li>" . $childmenu['name'] . "</li>";
    }        
    echo "</ul>";

}
但实际结果是这样的错误:

Menu 1
     menu 1a
     menu 1b
     menu 1c
Menu 2
     menu 2a
     menu 2b
......
菜单1

遇到一个PHP错误 严重性:通知 消息:未定义索引:子菜单 文件名:admin/vcategory_read.php 电话号码:34

A PHP Error was encountered
严重性:警告

消息:为foreach()提供的参数无效

文件名:admin/vcategory_read.php


从外观上看,行号为34。您的
$query->result\u array()
返回一个资源。不能用作foreach的输入

A PHP Error was encountered