递归下拉菜单在Bootstrap Codeigniter上无法正确显示

I have issues displaying a dropdown menu generated by a recursive function using a database. The parents are shown correctly below the items, but not as nav items, but just as a basic list.

Here's the image with how it actually looks: enter image description here

And here's how it SHOULD look:

enter image description here

Some relevant code:

Model:

<?php
class New_menu_model extends CI_Model {
    function get_domains() {
        $result = $this->db->get ( 'domenii' );
        return $result->result_array();
    }
}
    function recursive($parent, $result) {

        $has_children = false;
        foreach ( $result as $key => $value ) {
            if ($value ['parent'] == $parent) {
                if ($has_children === false && $parent) {
                    $has_children = true;
                    echo '<ul>' . "
" ;
                }
                echo '<li>' . "
";
                echo '<a href="/menu/domenii/' . $value ['id_domeniu'] . '">' . $value ['nume_domeniu'] . '</a>' . " 
";
                echo "
";
                recursive ( $key + 1, $result );
                echo "</li>
";
            }
        }
        if ($has_children === true && $parent)
            echo "</ul>
";
    }

?>

View:

 <li class="dropdown"><?php echo recursive(0, $menu); ?></li>

Thanks!

It should be something like:

<li class="dropdown">

     <a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">
          Dropdown <span class="caret"></span>
        </a>
        <ul class="dropdown-menu">
         <?php echo recursive(0, $menu); ?>
       </ul>
</li>

...and check echo '<ul>' . " " ; , it could be echo '<ul class="dropdown-menu">' . " " ; so the code should be:

 <li class="dropdown">

         <a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">
              Dropdown <span class="caret"></span>
            </a>

             <?php echo recursive(0, $menu); ?>

    </li>