Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>But then again, it doesn't feel like good MVC practice.</p> </blockquote> <p>Totally agree, the Model's the wrong place for such presentation concerns and storing both an HTML and a raw version of every variable would make it easy for them to get out of sync. Forget solution 2.</p> <p>That leaves you with alternative templating engines, or sticking with PHP and learning to bear the load of calling htmlspecialchars all the time. I'm open to the idea of alternative templating entries, but the ones I've tried so far I haven't really been happy with.</p> <p>(Many discard PHP syntax and implement their own limited expression languages, which means you lose the advantage of the language you already know and are stuck with a noddy-language which makes more complex presentation logic impossible, so you end up doing it yourself in PHP with strings full of HTML, which is absolutely not a win.)</p> <p>So for the moment I'd suggest a <strong>Solution 0a</strong> to add to the pile: define a global function with a short name to take the pain out of HTML-escaping:</p> <pre><code>&lt;?php function h($s) { echo(htmlspecialchars($s, ENT_QUOTES)); } ?&gt; ... My lovely variable is &lt;?php h($this-&gt;myVariable); ?&gt;. </code></pre> <p>I've no idea why PHP doesn't define a shortcut for this, which is as you say by far the most common use case. Now they've dumped the short-tags for XML-PI-style tags, why isn't there one with another name to do the right thing, like say <code>&lt;?phph</code>?</p>
 

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