This is more of a style question. I like to remove all possible logic from my output pages. All I really like my html pages to show are class instances/objects. This is especially the case when looping through result sets. I don't like the while's/for's to appear in my html page. Here's an example of what I mean:
Class Method:
<?php
class query_tool
{
// Members
// Constructor
// Methods...
function fetchTypes()
{
foreach ($this->aType as $nIdx => $sVal)
{
echo (OP_OPEN).$nIdx.(OP_CLOSE).$sVal.(OP_END);
}
}
}
?>
Where the OP_OPEN, etc are defined inside a config file. They are simply <option></option> tags.
So, in my html page all you see is:
<?php
$cQueryTool = new query_tool($parameters);
<select name="type" size="10" multiple>
<? $cQueryTool->fetchTypes() ?>
</select>
?>
Just a generic example. I want to know if this is the best way to return multiple results while removing all logic from the actual html page? Is there a better way of accomplishing this without the use of templates?
I have read an awful lot of misinformation, but one thing I've read is that echo'ing from within functions and methods is bad form. Not sure why or if this is true but I'd sure like to get some more feedback on this.
Thanks for your time!