Re: Couple of beginner questions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

Good luck,

John Corry

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux