I create a dynamic menu in the folder of library in codeigniter framwork.
class Left_menu {
private $ci;
function __construct()
{
$this->ci =& get_instance(); // get a reference to CodeIgniter.
}
function get_company ()
{
$html_out = '';
$company = $this->ci->db->query("select * from perusahaan");
$html_out .= "<ul class='sub_list'>";
foreach ($company->result() as $row)
{
$id = $row->id;
$name = $row->name;
$location = $row->location;
$html_out .= "<a href='".site_url("perusahaan_controller/detailPersahaan/".$id."")."'>";
$html_out .= "<li>".$name."</li>";
$html_out .= "</a>";
}
$html_out .= "</ul>";
$html = $html_out;
//print_r ($html);
return $html;
}
}
And the in the view I call it:
<?php $this->left_menu->get_company(); ?>
However, it doesn't show the menu at all. It does if only I print it, //print_r ($html);
, and the weird is it printed the menu as how I want to return it. (It looks like it turns the return
function into print_r).