Question

I am creating a view helper to deal with returning some data screen scraped from elsewhere and my question is, what is the best way to gather the collected data and return it for use in the view?

Assume the view helper goes out and successfully grabs a few divs full of data.

Should I return an array of data and iterate over that in the view?

$i = 0
foreach($this->myHelper as $noob) {
    echo '<div><h3>'.$noob[$i][0].'</h3><a href="'.$noob[$i][1].'">'.$noob[$i][2].'</a></div>';
    $i++;
}

or perhaps build the output in the view helper and return the whole lot as a string?

echo $this->myHelper;
/* giving me something like: 
    <div><h3>Foo1</h3><a href="bar1.htm">bar1</a></div>
    <div><h3>Foo2</h3><a href="bar2.htm">bar2</a></div>
*/

or return an object rather than an array or some other way I am missing (or screwing up in the above examples)? Thanks in advance.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top