PHP Newb - how to write a tag in PHP?

From: Date: Tue, 13 Nov 2007 02:06:37 +0000
Subject: PHP Newb - how to write a tag in PHP?
Groups: php.evangelism 
Request: Send a blank email to php-evangelism+get-459@lists.php.net to get a copy of this message
Hey, I am familiar with JSP web development and I want to learn PHP. The project I'm on has what seems to be questionable practices for the PHP. That's why I chose PHP evang list. First off, the PHP is concatenating HTML and JavaScript. We have some functions to generate the buttons. These use helper/util functions. Sample: $s = '<a href="#" id="' . $id . '" ' . $extra . ' onMouseOver="return Button.buttonChangeOver(this.id, '. $style . ');" onMouseOut="return Button.buttonChangeNormal(this.id, '. $style . ');" onMouseDown="return Button.buttonChangeDown(this.id, '. $style . ');" onMouseUp="return Button.buttonChangeOver(this.id, '. $style . ');" onClick="'.$callback.'">'; if ($pngImg) { $s .= $pngImg; } else { $s .= '<img id="' . $id . '-img" src="' . self::images($img) . '" border="0">'; One of the cleaner examples in the source code. If I were presented such code on a Java project, I'd be quick to recommend a .tag file, and pass the requisite objects to the tag (extract method [Fowler]). Util and helper static functions are a good indicator of poor design and usually lead to the type of spaghetti code I'm witnessing here (it's my first day today). Problem: How can I make a tag, or properly encapsulate the button functionality? My goal is to avoid mixing HTML in PHP code, but don't know the proper way in PHP. Is it possible? -- Programming is a collaborative art.

« previous php.evangelism (#459) next »