You can build tree based menus using the Tree helper See www.dereuromark.de/2013/02/17/cakephp-and-tree-structures/
echo $this->Tree->generate($categories); Am Dienstag, 15. April 2014 19:41:20 UTC+2 schrieb Naresh Kumar: > > > I am using CakePHP tree to generate my navigation menu . I have > generated it successfully. now i need to show them in navigation behavior. > I have tried. it is working but after this basic code i dont know what to > do after this .. how could i build navigation.. > > > *My HomeController.php* > > App::uses('AppController', 'Controller');class HomeController extends > AppController { > var $name='home'; > public function index() { > $this->layout = "front_end_index"; > $this->loadModel('Category'); > $category_tree = $this->Category->generateTreeList(); > $categories_array = array(); > foreach($category_tree as $k => $v) > { > $categories_array[$k] = $this->Category->find('first', > array('conditions' => array('Category.id' => $k))); > } > > $this->set('cat_info',$categories_array); > > }} > > *My category.ctp* > <?php foreach($cat_info as $cat_info) { if($cat_info['Category'][ > 'parent_id'] == ''){ ?> <ul class="menus"> <li><h4><?php echo $cat_info[ > 'Category']['name'] ;?></h4></li> <?php } ?> </ul> <?php } ?> > > *Navigation array sample :* > Array ( [1] => Array ( [Category] => Array ( [id] => 1 [parent_id] => [lft > ] => 1 [rght] => 42 [name] => My Categories [url] => http://google.com ) ) > [2] => Array ( [Category] => Array ( [id] => 2 [parent_id] => 1 [lft] => 2 > [rght] => 17 [name] => Fun [url] => http://google.com ) ) [3] => Array ( [ > Category] => Array ( [id] => 3 [parent_id] => 2 [lft] => 3 [rght] => 8 [ > name] => Sport [url] => http://google.com ) ) > > > -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.