I have a site written with mvc Codeigniter. I want that inside a view in a specific position call another view because for example the menu is repeated in many pages and is the same for all.
In my controller I have write this:
public function home()
{
$data['menu_function'] = $this->load->view('backend/include/menu_function_view');
$data['menu'] = $this->load->view('backend/include/menu_view');
$this->load->view('backend/include/header_view_logged');
$this->load->view('backend/home_view',$data);
$this->load->view('backend/include/footer_view');
}
and into my home_view
<?php
echo($menu_function);
?>
<div id="page">
<?php
echo($menu);
?>
<div id="content">
....
The problem is that the content inside $menu is out form page. I have seen that in firebug ithe html is like this:
<div id="menu">
...
</div>
<div id="page">
...
</div>
instead of:
<div id="page">
<div id="menu">
...
</div>
</div>
How can I solve It?
Don’t know if this the best approach but usually I use to create template file that load view in it. Here the basic idea:
in folder view I create file template.php that contains:
I then create folder view/include which contains:
file
header.php and footer.phpIn controller I call:
EDIT: The menu problem
How about passing the data like $menu_config to your header or view template.
header.php
On Controller: