One technique I have used where I want it to be as automatic as
possible (but possibly not compatible with any routing scenario) is
this:
My main menu consists of either plugins or controllers (some of each
kind.) So I use this to figure out what the current plugin or top-
level controller is:
---
if ( empty($this->plugin) ) {
$module_name = $this->name;
} else {
$module_name = $this->plugin;
}
---
Then I loop the currently available "modules" (controllers and plugins
that should be visible).
For each one I compare its name to the one extracted above and set the
class to selected if it matches.
---
foreach($modules as $one) {
$class = '';
if ( low($module_name) == low($one) ) {
$class = ' selected';
}
e('<li id="'.'main_menu_'.$one.'" class="main_menu_item'.
$class.'">');
e( $html->link(___('main_menu_'.$one),'/'.$one) );
e('</li>');
}
---
For the links I only need to go to the index action but there is
nothing stopping you from using more detailed menu-data to make more
complex versions of this technique.
What I like it that I don't need any specific (hard coded) information
in my layout. I can change out the available menuitems at any time. I
do this to adapt the menu to the permissions each user has. They only
need to see items that they actually can access. I construct the list
of available "modules" in AppController::beforeFilter after Auth has
done its thing.
/Martin
On Jan 14, 3:05 am, nurvzy <[email protected]> wrote:
> Thank you Miles!
>
> That technique is exactly what I was looking for!
>
> Nick
>
> On Jan 13, 5:04 pm, Miles J <[email protected]> wrote:
>
> > This is how I do mine:
>
> > // controller action
> > function login() {
> > $this->set('activeTab', 'login');
>
> > }
>
> > // the view
> > <li<?php if ($activeTab == 'login') echo ' class="selected"'; ?>><a
> > href="#">Login</a></li>
> > <li<?php if ($activeTab == 'signup') echo ' class="selected"'; ?>><a
> > href="#">Signup</a></li>
>
> > Also, your function would go in the bootstrap.php file in your app/
> > config/ folder.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---