Welcome Guest, Not a member yet? Register   Sign In
HTML in Helpers?
#2

[eluser]farinspace[/eluser]
I think keeping the HTML separate from the logic (business logic) based code is ideal, meaning you wouldn't want a function that gets data from a DB and at the same time write out HTML.

Functions that return objects and arrays are always much more useful, because you can then reuse those same functions for different things/views.

When it comes to PHP in views, I'm flexible, I usually use structural and formatting functions in the views (foreach, while, nl2br, etc) ... it's sometimes just easier to use PHP in your views, but I try to keep the PHP really plain vanilla, no heavy logic.

However, functions that return HTML, I think are fine too, consider this ... your functions in your helper can load view files and return them. Again you keep logic away from the HTML views/templates.

Also consider using "includes" with PHP, if you find yourself using a section of code more than once, put it into an include and use it in multiple locations.

Also take a look the the CI template parser, might be of interest/use ...


Messages In This Thread
HTML in Helpers? - by El Forum - 03-26-2010, 03:48 AM
HTML in Helpers? - by El Forum - 03-26-2010, 08:53 AM



Theme © iAndrew 2016 - Forum software by © MyBB