i wrote some code in codeigniter
index controller using model 'navigation':
$this->load->model('navigation');
$data['template']=$this->navigation->nav_template();
the nav_template() function generate string that will be output in brower:
function nav_template($uplevel=0)
{
$tablename=$this->db->dbprefix("test");
$sql="select * from $tablename where id_parent=$uplevel "
$menu_item=$this->db->query($sql);
foreach($menu_item->result_array() as $row)
{
if($something)
{
if
{
echo 'some str';
}
self::nav_template($uplevel);//call self
}
else
{
echo 'other str';
}
}
echo '</ul>';
}
in view file i am using an <?php echo $template ?>
but as we all known , i am using echo() to output string. i wanted to store the string in some php varialbe that can be used in view file template tag.
and the nav_template() function just called itself using self php keyword.
nowhere to define the var like this:
$template=''; and no where to return the string?
so , can anyone tell me how to return the output string within the nav_template() instead of echo it directly to browser?
ps: the output data is the formatted html code that will generate a treeview with help of some javascript scripts.
Originally asked by: tunpishuang on Stack Overflow


Answers