1

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

enter image description here

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.

1 Answer 1

1

First of all its never a good practice to call controller method directly in ctp (view) file.

If you still want to do this, try to call like this:-

Controller name::(scope resolution operator) function name(parameters). 

Note:-Make sure that your method is public.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.