I've created an element for my site masthead that includes the main
navigation as an unordered list following gwoo's advice in this
thread:

http://groups.google.com/group/cake-php/browse_thread/thread/fd6a65dc007f33ec

This works great but I am stumped at how to show active state when
browsing a section or its subsections.

At first I was calling $this->renderElement('masthead') from a layout
and I decided that the layout wouldn't know what section of the site
it was called from, so I moved renderElement out of the layout and put
it at the top of all my front-end views. This didn't help much.

Now I think the real problem might be the way I have the site
structured. At anyrate I'm stumped and out of ideas. I'm sure there's
a really elegant solution hiding in plain sight but after mucking
though debug($this) I realize that I'm aiming for a bad hack--if it
works at all.

To give an idea of what I'm looking to do, basically I'm putting my
design portfolio site into a database. You can see the static xhtml/
css version here:
http://www.graphic-manifesto.com/books/

Basic structure: I have a Medium model for the main sections and a
Project model for the sub-sections in each main section. A Medium
hasMany Projects and a Project belongsTo a Medium.

When you click a Media related link in the main navigation it routes
to the MediaController view method. But when you then click on the sub-
navigation in that section and you go to a specific project it routes
to the ProjectsController view method.

Here is some of the code I'm working off:

// @ app/views/*/*.thtml

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

// @ app/views/elements/masthead.thtml

<div id="header">

        <a href="/"><img src="/img/logo.gif" /></a>

        <ul class="textNavigation">
        <?php
        $media = $this->requestAction('media/index');
        $count = 1;
        foreach ($media as $medium):
                ?>
                <li<?php if ($count == 1) { echo ' class="first"';}?>><?php
                        echo 
$html->link($medium['Medium']['name'],'/projects/media/' .
$medium['Medium']['slug']);
                ?></li>
                <?php
                $count++;
        endforeach; ?>
                <li><a href="/pages/contact_no_js.htm" 
id="contactLink">Contact</a></
li>
        </ul>
</div>

// @ app/conrollers/media_controller.php

function index() {
        $media = $this->Medium->findAll('published = 1');
        if(isset($this->params['requested'])) {
                return $media;
        } else {
                $this->set('media', $media);
        }
}

//

There doesn't seem to be a good way to test what section the user is
browsing that would work from both controllers. Do I have to resort to
storing the location in the Session or is there a better way?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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