Hi,
I've been working with php for about a year now and am finally starting to make some headway in my understanding of OOP. So, now that I'm writing classes I'm looking for the cleanest methods of working my PHP into my HTML. I essentially have written a few classes that output data stored in my database.
For instance I'll instantiate an instance of a "user" class for which I'd written a function called getUserNameByIndex($index) which "echos" a value that I can then write into my HTML in my preferred manor like:
<h1> The <?php $user->getUserNameByIndex($index) ?> is not online </h1>
That's great. What's bumming me out is if I have an array of strings I need returned I then need to write more PHP into my HTML, making my output page look more like another PHP script.
For instance:
<span> His likes are:<br> <?php foreach($user->likes as $like){ if($like != foo){echo $like . '<br>' }} ?>
It just doesn't seem as clean to me, but if I write the output into the class method, I'm taking away some of my style control. I'm wondering if there is a balance here I should be looking for. Or if there is a standard method for handling arrays of strings that you intend to display in your HTML. I hope this makes sense and is not a dumb question. I'm so thrilled to be writing HTML that looks like HTML again, that anyway to minimize the PHP footprint in my code is a big bonus.
Thanks for your consideration.