Have you tried Smarty (smarty.php.net)?
-----Original Message-----
From: Sancar Saran [mailto:[EMAIL PROTECTED]
Sent: Tuesday, October 10, 2006 3:43 PM
To: [email protected]
Subject: [PHP] Seperate HTML from PHP
Hi there, following words are my ideas about that HTML PHP parting. I hope
you
can understand my broken english and do not take personally.
SEPERATING html FROM php ARE USELESS
For years, some php users try to show php to look like other programming
languages like C or JAVA. I believe they try to prove PHP can act like other
programming languages because most professionals from other disciplines
thinks that thing PHP was so easy to write to someting and because of this
that PHP thing can't be a professional tool.
To show professionalisim of php, people start to make programs using 3 tier
programming aproach. Then that MAGIC WORD seperating business layer from
presentation layer comes to php land...
After some time community sees templating engines, today you will see lots
of
them oh sorry TONS of them...
I'm sorry guys, I admire your efforts, REALLY.
Personally I spend more than 2 years to create some kind of OO library to
making forms easly. And after some time I realize, we cannot standardize
HTML/Javascirpt, every new project we have to challange to new interface
problems and because of this I have to redesign that templating library to
not broke code integritiy. Of course I may use that common library's to
solve
problems and of course later or sooner I find myself into a deep trouble.
That new project can't fit that lib.
And of course that was not only problem about templating engines.
They are slow, hell yes SLOW. (yea yea I know your uber template system
blazingly faster than more popular ones). You have to open tons of mini tpl
files, have to parse them, have to manage them.
So if that templating system generates this much of problem why we should
use
them ? Just Because of our uber HTML designer can't understand php ?.
I'm sorry, things are changing, nearly all new project are contains dynamic
parts. These visual designers have to learn some degree of php code.
And also I believe we have to change aproaching and usage of php language.
I see most people using php dynamic part of their html code. They using php
like
<a href="somepage.php?a=<?php echo $foo; ?>"><?php echo $bar; ?></a>
And I suggest we can aproaching html marking language to part of php
presentation layer.
Like
<?php
...
generate $head
generate $header
generate $left
generate $content
generate $right
generate $footer
...
include('theme.inc.php')
print $strOutput;
?>
theme.inc.php
<?php
$strOutput="<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\">
<head>
".$head."
</head>
<body>
<div id='mainDiv' class='cMainDiv'>
<div id='headDiv' class='cHeadDiv'>
".$header."
</div>
<div id='contDiv' class='cContDiv'>
<table border='0' cellpadding='0'
cellspacing='1' width='100%'>
<tr>
<td id='contLeftTD'
class='cContLeftTD' valign='top'>
".$left."
</td>
<td id='contCentTD'
class='cContCentTD' valign='top'>
".$content."
</td>
<td id='contRightTD'
class='cContRightTD' valign='top'>
".$right."
</td>
</tr>
</table>
</div>
<div id='footDiv' class='cFootDiv'>
".$footer."
</div>
</div>
</body>
</html>";
?>
Also we can use php to generate some kind of html code to reduce our
workload,
I believe best aproach was, do not generate data and html code in same
function...
Seperating html generation and data generation best way to increase code
reuse.
For example
function makeSelects($arrData,$strRequest)
{
$intSize = sizeof($arrData);
for($intS=0;$intS<$intSize;$intS++)
{
@$strReturn.="<option value='".$arrData[$intS]['val']."'";
if(@$strRequest == $arrData[$intS]['val']) { $strReturn.= "
selected"; }
$strReturn.= ">".$arrData[$intS]['tex']."</option>\n";
}
return $strReturn;
}
with this function we can generate select options.
$sqlGetType = "
SELECT typeId,typeName
FROM listType
WHERE typeStatus = 'active'
ORDER BY typeName ASC";
$resGetType = doSql($sqlGetType); // put your sql extraction function here
$intT = 0;
while(!$resGetType->EOF)
{
$arrType[$intT]['val'] = $resGetType->fields[0];
$arrType[$intT]['tex'] = $resGetType->fields[1];
$intT++;
$resGetType->MoveNext();
}
$strType = makeSelects($arrType,@$_REQUEST['type']);
echo "<select name='type' size ='1'>
".$strType."
</select>";
examples may go further.
And please, do not think seperating Html from php and is good thing. All of
them part of the system.
Or just think, can we seperate SQL from php ?, is there any SQLling template
or someting like that library available? If I remember correctly that SQL
was
another language.
And of course my ideas has tons of objection and I think this way.
Thanks to reading my ideas about php and html seperation. I hope I can
translate my ideas about the issue.
Regards
Sancar "Delifisek" Saran
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php