HTML time-savers are useful, but they’re only useful when they’re intuitive and easy-to-understand. Having to instantiate a
new Draw just doesn’t sound very natural. Furthermore,
left will only have significance to someone who intimately knows the system. And what if there is a redesign, like your co-worker muses? What if the
wideHeaderBox becomes very narrow? Will you change the markup (and styles, presumable) generated by the PHP method but leave a very inaccurate method name to call the code?
If you guys just have to use HTML generation, you should use it interspersed in view files, and you should use it where it’s really necessary/useful, such as something like this:
HTML::link("Wikipedia", "http://en.wikipedia.org"); HTML::bulleted_list(array( HTML::list_item("Dogs"), HTML::list_item("Cats"), HTML::list_item("Armadillos") ));
In the above example, the method names actually make sense to people who aren’t familiar with your system. They’ll also make more sense to you guys when you go back into a seldom-visited file and wonder what the heck you were doing.
The argument he uses is the argument you need to have views. Both result in only changing it in one place. However, in his version, you are mixing view markup with business code.
I would suggest using more of a templated design. Do all your business logic in the PHP, setup all variables that are needed by your page. Then just have your page markup reference those variables (and deal with no business logic whatsoever).
Have you looked at smarty? http://smarty.php.net
I’ve done something like that in the past, and it was a waste of time. For instance, you basically have to write wrappers for everything you can already with HTML and you WILL forget some things. When you need to change something in the layout you will think “Shoot, I forgot about that..now I gotta code another method or add another parameter”.
Ultimately, you will have a huge collection of functions/classes that generate HTML which nobody will know or remember how to use months from now. New developers will curse you for using this system, since they will have to learn it before changing anything. In contrast, more people probably know HTML than your abstract HTML drawing classes…and sometimes you just gotta get your hands dirty with pure HTML!