Following the same example, I've come up with something more dynamic -
but unfortunatly I cannot seem to get it to work, can anyone help me?

First of all, I call the element:

<?php echo $this->renderElement('topmenu'); ?

Then in the element, I call my menu section manager and request all
menu's (through a hABTM association) to an array:

<ul>
<?php
       $menus = $this->requestAction('sections/rendermenu/topnav');
           print_r("output: " . $menus);
       foreach($menus['Section']['Menu'] as $menu) {
                print "<li>";
                if ($menu['path'] == $this->here){
                       echo
$html->link($menu['name'],$menu['path'],'class="active"');
                }else{
                       echo $html->link($menu['name'],$menu['path']);
                                }
               print "</li>";
       }
?>
</ul>

The last param calls the search in the controller:

<?php

class SectionsController extends AppController
{
        var $name = "Sections";
        
        
        function rendermenu($id)
        {
                $menus = $this->Section->findAll(array('name'=>$id));
                
                if(isset($this->params['requested'])) {
                        return $menus;
                }
                
                $this->set('menus', $menus);
                
                //print_r($menus);
        }
        
}
?>

Now, I get an array back, but I get a foreach error:

Array ( [0] => Array ( [Section] => Array ( [id] => 1 [name] => topnav
) [Menu] => Array ( [0] => Array ( [id] => 1 [name] => Home [path] =>
/ ) [1] => Array ( [id] => 2 [name] => News [path] => /posts/ ) ) ) )

Warning (2): Invalid argument supplied for foreach()
[CORE/app/views/elements/topmenu.ctp, line 5

Anyone?

Thanks very much,
Tane



On 3/20/07, stevenoone <[EMAIL PROTECTED]> wrote:
>
> I tried this solution and whaddya know: if worked! here's my code.
> //invoke menu element
> <?php echo $this->renderElement('menu'); ?>
>
> //menu.thtml
> <ul>
> <?php
>         $controls = $this->requestAction('controls/navindex');
>         foreach($controls as $control) {
>                 print "<li>";
>                 if ($control['Control']['path'] == $this->here){
>                         echo 
> $html->link($control['Control']['name'],$control['Control']
> ['path'],'class="active"');
>                 }else{
>                         echo 
> $html->link($control['Control']['name'],$control['Control']
> ['path']);
>                 }
>                 print "</li>";
>         }
> ?>
> </ul>
>
> On Mar 19, 5:19 pm, "gwoo" <[EMAIL PROTECTED]> wrote:
> > This has come up a lot lately for some reason. I guess because there
> > are not enough examples.
> >
> > Personally, I would setup and element. Lets calll it /app/views/
> > elements/menu.thtml
> > add to this:
> >
> > $controls = $this->requestAction('controls/index');
> > foreach($controls as $control) {
> > //do whatever}
> >
> > very simply this asks the controls controller to return the index
> > method so you can display the data however you want
> >
> > <?php
> > class ContolsController extends AppController {
> >
> > function index() {
> >
> >     $contols = $this->Control->findAll();
> >
> >     //here is where the requesAction is handled so only the data is
> > returned
> >     if(isset($this->params['requested'])) {
> >         return $controls;
> >     }
> >
> >     $this->set('controls', $controls);
> >
> > }
> > }
> >
> > ?>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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