Web lists-archives.com

Re: [PHP] MVC: code in views

On Sun, 2016-01-03 at 17:10 -0500, Stephen wrote:
> On 16-01-03 04:43 PM, Ashley Sheridan wrote:
> > Hi all,
> >
> > Just wanted to get some thoughts from others on the list. Recently I've
> > been trying to avoid using any PHP code at all in my views at all, not
> > even an if statement or for loop....
> My work is not all that complex, but early on I decided to keep the PHP 
> code and the HTML as separate as possible. It makes things much easier 
> when I am adding pages, or creating a new web site.
> I use CSS for all of the layout and styles of course.
> The HTML is in a variable that I call $markup, and within that variable 
> are more variables that are populated by the PHP and contain the actual 
> content.

I'm still keeping the HTML separate where possible, not a single tag is
hard-coded into the PHP, and the HTML view files look like this:

<div class="l-container">
  <p>some text</p>
<ul class="l-list--floated unstyled">

The template parts are then handled by class methods. 

Anything that would then require building HTML (like the form, for
example) is built out of tons of snippets for the overall form and each
element. This does mean loads of view snippets, but I think that's an
acceptable trade-off.



PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php