Not sure if this answers your query but have a look @
http://book.cakephp.org/view/1023/find-threaded


On Aug 23, 10:29 pm, nightshadex101 <[email protected]> wrote:
> Hi All,
>
> I'm trying to build a menu system.
> I've already created a table in the database, a model (with tree
> behavior), and a controller.
>
> The idea is that the menu has 2 levels (it will probably get 3 levels
> later), and the following is showed:
>
> -All parent of 1st level pages (controllers)
> If I'm on a parent page (ie: a controller)
>     -All my children/2nd level pages (funcions in that controller)
> If I'm on a 2nd level page
>     -All the other children of my parent (all the other functions in
> that controller)
>
> What I'm not getting is how to call this function from an element (to
> later insert in the layout) so that I can pass the current page to the
> controller function.
>
> This is the db table:
>
> CREATE TABLE IF NOT EXISTS `menus` (
>   `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
>   `parent_id` int(10) DEFAULT NULL,
>   `lft` int(11) DEFAULT NULL,
>   `rght` int(11) DEFAULT NULL,
>   `name` varchar(255) COLLATE latin1_general_cs DEFAULT '',
>   `location` varchar(255) COLLATE latin1_general_cs DEFAULT '',
>   `status` tinyint(1) NOT NULL,
>   `created` datetime DEFAULT NULL,
>   `modified` datetime DEFAULT NULL,
>   PRIMARY KEY (`id`)
>
> Model:
>
> <?php
> class Menu extends AppModel {
>         var $name = 'Menu';
>         var $actsAs = array('Tree');}
>
> ?>
>
> Controller:
>
> <?php
> class MenusController extends AppController {
>
>         var $name = 'Menus';
>
>         function getMenu($location = null) {
>                 if(substr($location,-1,1) == '/')
>                         $location = substr($location,0,strlen($location)-1);
>                 $locationId = $this->Menu->field('id', array('location' =>
> $location));
>                 $allParents = $this->Menu->find('all', array(
>                         'fields'         => array('Menu.id', 'Menu.name', 
> 'Menu.location'),
>                         'conditions' => array('Menu.parent_id' => null, 
> 'Menu.status'      =>
> 1)
>                 ));
>                 $myParent = $this->Menu->getparentnode($locationId);
>
>                 if ($myParent) {
>                         $secondLevel = 
> $this->Menu->children($myParent['Menu']['id'],
> true);
>                 } else {
>                         $secondLevel = $this->Menu->children($locationId, 
> true);
>                 }
>
>                 $secondLevelFiltered = array();
>                 $i = 0;
>                 foreach ($secondLevel as $children) {
>                         if ($children['Menu']['status'] == 1) {
>                                 $secondLevelFiltered[$i]['id'] = 
> $children['Menu']['id'];
>                                 $secondLevelFiltered[$i]['name'] = 
> $children['Menu']['name'];
>                                 $secondLevelFiltered[$i]['location'] = 
> $children['Menu']
> ['location'];
>                                 $i++;
>                         }
>                 }
>
>                 $menuTree = array();
>                 $i = 0;
>                 foreach ($allParents as $parent) {
>                         $menuTree[$i] = $parent['Menu'];
>                         if ($myParent) {
>                                 if ($myParent['Menu']['id'] == 
> $parent['Menu']['id']) {
>                                         $menuTree[$i]['children'] = 
> $secondLevelFiltered;
>                                 }
>                         } else {
>                                 if($locationId == $parent['Menu']['id']) {
>                                         $menuTree[$i]['children'] = 
> $secondLevelFiltered;
>                                 }
>                         }
>                         $i++;
>                 }
>                 return($menuTree);
>         }}
>
> ?>
>
> Could someone give me some orientation on how to procede from here?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to