Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to create complex container in php
    primarykey
    data
    text
    <p>I'm creating a container type which has a lot of possible variations on what can be included:</p> <ul> <li>title bar</li> <li>search bar</li> <li>form bar</li> <li>tab bar</li> <li>custom bar</li> <li>info bar</li> <li>action/status bar</li> <li>content area</li> </ul> <p>Of these, only the content area is required. There are sub-types that would share common sets of bars, but they can also be mixed and matched in arbitrary combinations. Also, each bar-type can have content on either the left or the right side. </p> <p>I've been going down the path of creating a Panel class with properties like:</p> <ul> <li>info_left</li> <li>info_right</li> <li>search_left</li> <li>search_right</li> <li>etc.</li> </ul> <p>then doing this kind of logic:</p> <pre><code>// snip from __toString() if ($this-&gt;info_left || $this-&gt;info_right) { $result .= $this-&gt;add_bar('info', $this-&gt;info_left, $this-&gt;info_right); } if ($this-&gt;search_left || $this-&gt;search_right) { $result .= $this-&gt;add_bar('search', $this-&gt;search_left, $this-&gt;search_right); } // end snip private function add_bar($type, $left, $right) { $result = &lt;&lt;&lt; HERE &lt;div class="$type"&gt; &lt;div class="left"&gt;$left&lt;/div&gt; &lt;div class="right"&gt;$right&lt;/div&gt; &lt;/div&gt; HERE; } </code></pre> <p>and to instantiate a Panel:</p> <pre><code>$p = new Panel("my panel"); $p-&gt;info_left = "my left content"; $p-&gt;search_right = "my right search content"; echo $p; </code></pre> <p>So far, I've stayed away from using a template engine because the logic seems complex enough that I'd almost rather keep it in the class. (The class has very little business logic, but lots of presentation logic.) Maybe there's a better approach....? </p>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    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