My method is
public function topmenu($parentsid=null){
$this->layout =false;
$category_tree = $this->Categorymaster->find('all',array('order'=>'Categorymaster.lft ASC','conditions'=>array('Categorymaster.parent_id'=>$parentsid)));
echo '<ul class="sub-menu" role="menu">';
foreach($category_tree as $parentval){
echo '<li>'.$parentval['Categorymaster']['name'].'</li>';
$id = $parentval['Categorymaster']['id'];
$haschild = $this->Categorymaster->children($id, true);
if (!empty($haschild)) {
$this->topmenu($id);
}
}
echo '</ul>';
$this->set(compact('category_tree'));
$this->render('topmenu');
}
I get output from controller

I am trying to use a foreach loop in my topmenu.ctp file but as cakephp
is mvc it gives error at the lines
$haschild = $this->Categorymaster->children($id, true);
if (!empty($haschild)) {
$this->topmenu($id);
}
so how can it use topmenu() method in .ctp file so that i can show it in my menu or any other alternative.