Passing variables to a layout from the controller in Zend Framework

This is easier than it seems, and pretty cool too!
A great use for this type of thing would be for instance a Navigation Breadcrumbs section.

In your controller, you would add something similar to the following:

Zend_Layout::getMvcInstance()->assign('nav', '<a href="/home">Home</a> | <a href="/something">Something Else</a>');

Then in your layout.phtml or view partial, you can say:

if(isset($this->layout()->nav)){echo $this->layout()->nav; }

More awesomeness! We hope you enjoyed your meal. Be sure to drop by again!

Advertisements

3 thoughts on “Passing variables to a layout from the controller in Zend Framework

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s