Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You ask various questions in this single post. I will try to address a few of them.</p> <p><strong>How does a layout work?</strong></p> <p>In Zend Framework 2 there is the concept of "view models". A view model is an object that has a couple of variables and a template assigned. This template is rendered with the given variables.</p> <p>Furthermore, you can nest view models. So one view model (the "layout") has a child which is created from your controller. The child is rendered and stored as a variable in the parent view model. The name of this variable is called the "capture to".</p> <p>What happens, is you have a controller and then a view model is created. This view model is inserted as a <em>child view model</em> in a new model, which is the layout. This child is set with a "capture to" of <code>content</code>. So in the layout, the result of the child view model is inserted in the <code>$content</code> variable.</p> <p><strong>How do you access layout variables in the controller?</strong></p> <p>There is a a <code>layout</code> controller plugin which gives you <em>direct access to the layout view model</em>. So you can set variables directly there:</p> <pre><code>public function indexAction() { $this-&gt;layout()-&gt;setVariable('foo', 'bar'); } </code></pre> <p>Then <code>$foo</code> echos <code>bar</code> in your layout.</p> <p><strong>How do you access layout variables in a view script?</strong></p> <p>There is a a <code>layout</code> view helper which also gives you <em>direct access to the layout view model</em>. So you can set variables there too:</p> <pre><code>&lt;?php $this-&gt;layout()-&gt;foo = 'bar';?&gt; </code></pre> <p>Then <code>$foo</code> echos <code>bar</code> in your layout.</p>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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