Welcome Guest, Not a member yet? Register   Sign In
controller vs view for loops
#1

[eluser]new_igniter[/eluser]
Hello,
I am curious if people know which of the following scenarios is faster.

1. looping through results in the controller, building the HTML, and passing the HTML to the view and just echoing the HTML

or

2. constructing an array in the controller and looping through the results in the view

Thanks!
#2

[eluser]Derek Allard[/eluser]
They're probably insignificantly different (you could benchmark this though) but the second option is probably both more maintainable, and more "correct" by MVC standards.
#3

[eluser]new_igniter[/eluser]
thanks!
#4

[eluser]drewbee[/eluser]
Agreed. I would rather loop in the view... it tends to be a lot cleaner as well then rather building a string and passing it to it.

All HTML should be maintainable from the view. Doing it at the controller seems kind of backwards.
#5

[eluser]WanWizard[/eluser]
And something I bumped into on a previous project:

it becomes a nightmare if the programmer and the webdesigner are two different people. You don't want the webdesigner to mess with the code, you want clear separation of logic and presentation.

One of the reasons I'm now a great fan of Smarty (with PHP support turned off Smile).




Theme © iAndrew 2016 - Forum software by © MyBB