[eluser]wiredesignz[/eluser]
I'm not going to try to teach you MVC here, but there are far better ways to achieve templating.
Call the model from the view
Code:
//view
<ul>
<?php
if ($items = $this->menu_model->get_data(array('site','nav'))):
foreach ($items as $k => $item):
$active = ($item->uri == $page) ? array('class' => 'current') : NULL;
echo '<li>', anchor($item->uri, $item->title, $active), '</li>';
endforeach;
endif;
?>
</ul>
Pass the data into the view
Code:
//controller
$data['items'] = $this->menu_model->get_data(array('site','nav'));
//view
<ul>
<?php
if ($items):
foreach ($items as $k => $item):
$active = ($item->uri == $page) ? array('class' => 'current') : NULL;
echo '<li>', anchor($item->uri, $item->title, $active), '</li>';
endforeach;
endif;
?>
</ul>
Pass a reference to the model into the view
Code:
//controller
$data['menu'] =& $this->menu_model;
//view
<ul>
<?php
if ($items = $menu->get_data(array('site','nav'))):
foreach ($items as $k => $item):
$active = ($item->uri == $page) ? array('class' => 'current') : NULL;
echo '<li>', anchor($item->uri, $item->title, $active), '</li>';
endforeach;
endif;
?>
</ul>