Code Comments
Programming Forum and web based access to our favorite programming groups.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.
Post Follow-up to this messageHi
Not entirely sure I understood the question correct, but the normal pratice
in php,
is to write ViewHelpers , example:
<?php
>
> class View_Helper_Button extends View_Helper
> {
> function button($id,$style,$extra,$img,$pngImg=nu
ll)
> {
> $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">';
> }
> return $s;
> }
> }
>
> ?>
Then you can simple build this in your view-render if you're using a
classical MVC.
The ViewHelper from above would then be used like this
<span>Click on the button to continue</span>
> <?php
> echo $this->button('foo','','');
> ?>
Which appears very clear in my eyes. Else you need a framework like PRADO to
build your own personal xml-syntax and elementals, for the said buttons.
I personaly recomend the php way, it's alot faster.
I hope this answered your question. If you wish to look more into
ViewHelpers,
check the frameworks, Zend_Framework and Symfony.
--
Sincerely
Claus Jørgensen, Denmark
http://www.dragons-lair.org
2007/11/13, Garrett Smith <dhtmlkitchen@gmail.com>:
>
> 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.
>
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.