Why not using "for_layout" variables?

Just set into your controller action a "selectedtab_for_layout"
variable and inside the
layout (yes i said layout, not view) you can access it.


On Jan 14, 5:42 pm, teknoid <teknoid.cake...@gmail.com> wrote:
> If I understand this right, you are looking to set an "active" tab,
> based on the view you are currently in...
>
> It can be done easily from the view itself, i.e. in view_one.ctp:
> $this->set('tabOne', true); (which is now going to be available in
> your layout).
> Therefore, in the layout you could do: <?php echo isset($tabOne) ?
> 'class="selected-tab"' : null; ?>
>
> On Jan 13, 6:05 pm, nurvzy <nur...@gmail.com> wrote:
>
> > Hi All,
>
> >   I'm new to cakephp and working through my first cake app.  I'm
> > chugging along and am now stumped as to where to put a function I've
> > written to help decide if a navigation tab should have the
> > id="selected" assigned to the anchor tag.
>
> > Basically the gist is I have a <ul> Navigation bar with various links:
> > (Home, Contact, ect..) and depending on the current controller or
> > action or whatever I pass in; I want the id of that <a> tag to be
> > "selected".
>
> > So I've written a little function:
>
> > function is_selected($controller_or_action, $link_text){
> >   if (strpos($controller_or_action,$link_text) !== false) return true;
> >   else return false;
>
> > }
>
> > And I'm calling it like so in the default.ctp layout:
>
> > <?php
> >  if(is_selected($this->params['controller'], "pages")) echo $html->link
> > ('Contact', array('controller' => 'pages', 'action' => 'contactus'),
> > array('id' => 'selected'));
> > else echo $html->link('Contact', array('controller' => 'pages',
> > 'action' => 'contactus'));
> >  ?>
>
> > But that's really tedious and quite ugly, plus I have that function
> > just written at the top of the layout which is a big no-no.  So I'm
> > looking for some help/advice.  How do you specify a tab type layout in
> > your cake app?
>
> > Thank you for your advice and/or help.
> > Nick
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to