Search code examples
phphtmlmodel-view-controllerstandardsconventions

Cases where HTML is not frowned upon inside of php?


I know that control stuff should be separated from view stuff, but there's so many cases where I know it's slower and over-complicating to do things with html templates.

My question is... where is it acceptable?

Examples of what I'm talking about... functions that output very dynamic tables, functions that create input elements, and functions that format text.

The only con I can think of, other than it being "ugly," is that I don't tab out and newline inside of these functions, which makes the output HTML a bit ugly. Most of the time when I face this, I just say forget convention - functionality wins in most cases.

Anyone have any insight or opinions on the topic to share?


Solution

  • I know it's more work, but the MVC pattern is much more maintainable in the long run. Even for dynamic tables, it would be better to create a class that can create any size table/list/divs and then pass your data to it than have view data in your model/controller.

    I sometimes cheat a bit on very small projects and mix in business logic with presentation, but if the project ever grows it usually is more work correcting it down the road. So unless I'm being really lazy, it's not that hard to be fairly strict with implementing code in an MVC manner.