Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In this case, I usually go with a <a href="http://devzone.zend.com/1224/front-controller-plugins-in-zend-framework/" rel="nofollow">front controller plugin</a> with a <code>dispatchLoopShutdown()</code> hook that performs the required data access and adds the data to the view/layout. The layout script then renders that data.</p> <p>More details available on request.</p> <p><strong>[UPDATE]</strong></p> <p>Suppose you wanted to display inside your layout the last X news items from your db (or web service or an RSS feed), <em>independent of which controller was requested</em>.</p> <p>Your front-controller plugin could look something like this in <code>application/plugins/SidebarNews.php</code>:</p> <pre><code>class My_Plugin_SidebarNews { public function dispatchLoopShutdown() { $front = Zend_Controller_Front::getInstance(); $view = $front-&gt;getParam('bootstrap')-&gt;getResource('view'); $view-&gt;sidebarNews = $this-&gt;getNewsItems(); } protected function getNewsItems() { // Access your datasource (db, web service, RSS feed, etc) // and return an iterable collection of news items } } </code></pre> <p>Make sure you register your plugin with the front controller, typically in <code>application/configs/application.ini</code>:</p> <pre><code>resource.frontController.plugins.sidebarNews = "My_Plugin_SidebarNews" </code></pre> <p>Then in your layout, just render as usual, perhaps in <code>application/layouts/scripts/layout.phtml</code>:</p> <pre><code>&lt;?php if (isset($this-&gt;sidebarNews) &amp;&amp; is_array($this-&gt;sidebarNews) &amp;&amp; count($this-&gt;sidebarNews) &gt; 0): ?&gt; &lt;div id="sidebarNews"&gt; &lt;?php foreach ($this-&gt;sidebarNews as $newsItem): ?&gt; &lt;div class="sidebarNewsItem"&gt; &lt;h3&gt;&lt;?= $this-&gt;escape($newsItem['headline']) ?&gt;&lt;/h3&gt; &lt;p&gt;&lt;?= $this-&gt;escape($newsItem['blurb']) ?&gt;&lt;/p&gt; &lt;/div&gt; &lt;?php endforeach; ?&gt; &lt;/div&gt; &lt;?php endif; ?&gt; </code></pre> <p>See what I mean?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload