Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

PHP Newb - how to write a tag in PHP?
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.

Report this thread to moderator Post Follow-up to this message
Old Post
Garrett Smith
11-13-07 03:23 AM


Re: PHP Newb - how to write a tag in PHP?
Hi

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.
>

Report this thread to moderator Post Follow-up to this message
Old Post
Claus Jørgensen
11-13-07 03:23 AM



Carmen Electra and Sar
ah M. Gellar Lesbians Doing In Jacuzzi!

Report this thread to moderator Post Follow-up to this message
Old Post
Zomo
01-11-08 06:50 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP Evangelism archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 10:10 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.