I am trying to create dynamic menu with database.

The ***Controller*** is menu.php

```
  <?php
  $_SESSION['lang'] = 'EN';

class Menu extends CI_Controller {
function __construct(){
    parent::__construct();
    $this->load->database();
    $this->load->model("menu_model");
}

public function index()
{
    $data['category']= $this->menu_model->getCategory('$lang');
    $data['subcategory']= $this->menu_model->getSubCategory('$lang');

    $this->load->view('vwHeader',$data);//Left Menu
}
}
?>

```

the ***Model*** is menu\_model.php

```
<?php
 class Menu_model extends CI_Model{
function __construct(){
    parent::__construct();
    $this->load->database();
}

function getCategory($lang){
    $sql = 'SELECT * FROM category';
    $result = $this->db->query($sql);
    if($result->num_rows() > 0)
    {

    return $result;
    }

}

function getSubCategory($lang){
    $sql = 'SELECT * FROM subcategory';
    $result = $this->db->query($sql);
   if($result->num_rows() > 0)
    {
   return $result;
    }

}

}
?>

```

the ***View*** is vwHeader.php

```
<?php

           foreach($category->result() as $menu)
{
echo "<ul style='margin-left: 148px;margin-top: 15px;'>";
   echo "<li style='float: left;

height: 57px;
text-decoration: none;
display: block;'><a class=\"sf-with-ul\" href=\"category/".$menu->urlcategory."\">".$menu->namecategory."</a>";
   /*check whether sub menu is there if so first print <ul> then <li><a>*/
   if(count($subcategory->result()) > 0 && is_array($subcategory->result()))
   {
         echo "<ul class=\"sub-menu\">";
        foreach($subcategory->result() as $key=>$submenu)
        {
          if ($menu->idcategory == $submenu->idcategory){
           echo "<li><a href=\"category/".$submenu->urlsubcategory."\">".$submenu->namesubcategory."</a></li>";
            }
         }

    }
    else
        {
        echo "<ul style='display:none'>";
        echo "</ul>";
        } 
        echo "</ul>";
    echo "</li>";
     echo "</ul>";
}

                    ?>

```

Now the error is,

> 
> Severity: Notice
> 
> 
> Message: Undefined variable: category
> 
> 
> Filename: views/vwHeader.php
> 
> 
> Line Number: 38
> 
> 
> Fatal error: Call to a member function result() on a non-object in C:\xampp\htdocs\admin\application\views\vwHeader.php on line 38
> 
> 
> 

how can i solve that????