Zend Layout and Navigation

I’m not sure how everyone else is using Zend_Layout, but I’m doing the following to render my navigation and footer links. It’s not the most DRY code, but works until I learn more about the framework.

In my Action file, I add actions to the stack for nav, footer, etc.

class IndexController extends ....
{
function indexAction()
{
$this->_helper->actionStack('main', 'nav', 'default');
$this->_helper->actionStack('footer', 'nav', 'default');
$this->_helper->actionStack('right', 'nav', 'default');
/* other stuff */
}
}

Then I have a NavController that simply calls setResponseSegment or renderScript to set the named variables.


class NavController ..
{
function footerAction()
{
/* Stuff to display */
$this->renderScript('nav/footer.phtml', 'nav');
// Or I could use
// $this->_helper->viewRenderer->setResponseSegment('nav');
}
}

This allows me to finally use the nav variable in my layout file
layout/default.phtml

echo $this->layout()->nav;

Simple eh?

One Response to “Zend Layout and Navigation”

  1. Annette Rio Says:

    HUEY!!! I haven’t heard from you in FOREVER! I ran across a link to your webpage on one of Ericka’s sites. I always knew you would end up doing something deep with computers that I would never understand. You were always SO TALENTED! It sounds like your life is going along wonderfully! I’m so happy for you! Congratulations on BOTH of your children! Being a parent is the greatest gift in the world.

    I would love to hear where you are and exactly what you’ve been doing. I hope you’ll shoot me an email sometime….

    netty

Leave a Reply