On Mon, Jan 12, 2009 at 12:04:15AM -0500, John Corry wrote: > One of the best things that ever happened to me (with regards to > writing PHP) was deciding not to embed it in HTML anymore. > > I either: > a) generate the HTML from classes I've built (HTML, Forms, Tables, > Images, etc) or use an equivalent PEAR class > > - or - > > b) Use Smarty templates...in which I still generate the HTML that will > go to the template (where required) with the HTML generation classes. > > The advantages are abundant. > > I can't imagine having to maintain some of the code I saw in the > examples above. My favorite WTF was with this snippet: > > $imgHTML = '<img src="' . $url . '" alt="' . $alt . '" title="' . $alt > . '" class="' . $imgclass . '" />'; > > Holy crap...REALLY!? > > All that string concatenation and there's not even width/height > attributes in there! > > That would look like: > > $i = new Image('path/to/image/file'); > $i->__set(array('class'=>$imgClass, 'alt' => $altText)); > $i->toHtml(); > > Being able to change every image tag in a site by editing the > class/method that created is just too big an advantage not to use. Not > to mention the auto-generated width/height attributes, the ability to > auto-produce thumbnails and fullsize images from a single file... > > After struggling through the beginnings, I wrote classes to generate > basic HTML elements, then tables, then forms, then images. > > It saved me a bunch of time and taught me to see the website as an > application...not as a web-page with pieces of data in it. > > Somehow, coming to that bit of knowledge was very helpful to my life > as a programmer. I've written a lot of code like the original example above, and still do, but I see your point, since I've written code like yours too. I write all my PHP code (and I write a *lot* of it) solo, with no help and no collaborators. But as I understand it from a lot of framework types, the ideal is to set up the HTML so that a HTML coder can understand what's going on, without having a lot of PHP weirdness in it. Meaning, if you're going to infuse your HTML with PHP, you should do it in a minimalistic way. It'd be a helluva lot easier on me to do it all through PHP classes, though. I also come from a C background, and I recognize significant differences between the paradigm for C programs and HTTP-based coding. Considering that every PHP "program" paints generally a single page, I'm not a fan of loading up 14 support files every time I load a page of HTML. That's why I don't use one of the MVC frameworks available in the FOSS world. CodeIgniter, which is one of the lightest weight frameworks, opens something like 17 files before it paints a single byte in the browser. The upshot is that I don't like to use a lot of libraries scattered in a variety of files to render HTML/PHP pages. But here's a question for those of you who work in a collaborative environment-- are you really ever in a situation where some HTML weenie is coding HTML pages and you're somewhere else doing the PHP work? Or is that some academic's view of the way things *should* be done? Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php