您對這段代碼有什麼看法?您對這段代碼的質量有什麼看法?
我知道這有html和php混合在一起。我們怎樣才能從PHP中分離HTML?還需要做些什麼來提高此代碼的質量?
希望這裏的一些PHP專家可以幫助我。
編輯:
只是想補充一點,在這個特殊的代碼業務邏輯已經成爲像AppointmentManager類獨立的文件,負責一切有關任命,建立刪除等等,等等
我放在這裏的代碼段(manage.php)只顯示約會的細節並允許編輯,取消它們。
現在,我不確定我們稱之爲該頁面,無論是顯示邏輯還是表示邏輯或其他任何....但我需要知道的是,如果它可以進一步分離HTML和PHP?
我可以做的事情,例如讓這片HTML出這個文件的...
<script language="JavaScript" src="ajax/core2.js"></script>
<h2 align='center'> Appointment Control Panel V 1.0</h2>
<h2 align='center'>Your Next Appointments</h2>
<div id=detail></div>
而且同樣休息吧......我的意思是完全獨立的HTML和PHP使主管和擴展應用程序很容易。
我不想使用Smarty,我認爲它不必要地使事情複雜化。
我可以創建一些PHP函數,當調用時呈現這個html,也許把它們放到一個像displayhtml.php這樣的常用函數文件中?
可能有其他更好的建議嗎?
<?php
/*
* manage.php
*
* Author: Bob : 2010-11-11
*
*/
ob_start();
$page_title = "Appointments Management";
require_once('appts/coreincs.inc');
require_once('appts/pagetop.inc');
$am = AppointmentManager::getInstance();
$appts = $am->getPendingAppointments($g_userID);
?>
<script language="JavaScript" src="ajax/core2.js"></script>
<h2 align='center'> Appointment Control Panel V 1.0</h2>
<h2 align='center'>Your Next Appointments</h2>
<div id=detail></div>
<?php
if ($appts === NULL)
{
echo <<<EOEMPTY
<p align='center'>
You have no upcoming appointments.
</p>
EOEMPTY;
}
else
{
/**
* List the appointments. Start the table.
*/
echo <<<EOT
<table align='center' width='80%' border='0' cellspacing='0'
cellpadding='3' class='apptTable'>
<tr>
<td width='25%' class='apptDispHeader'>When:</td>
<td width='30%' class='apptDispHeader'>Title:</td>
<td width='15%' class='apptDispHeader'>Action:</td>
<td width='25%' class='apptDispHeader'>Where:</td>
</tr>
EOT;
/**
* Zip through all the appointments and print them out.
*/
foreach ($appts as $appt)
{
//if ($appt->StartTime->sameDay($appt->EndTime))
//{
$start = $appt->FullTimestart;
$end = $appt->FullTimeend;
echo <<<EOAPPT
<tr>
<td>$start ==> $end</td>
<td>
<div id=title_{$appt->AppointmentID} loaded="t_{$appt->AppointmentID}">
<div id=title_{$appt->AppointmentID}_t_{$appt->AppointmentID}>
<a class='apptDispLink'
href='showappt.php?aid={$appt->AppointmentID}'>
{$appt->Title}
</a>
</div>
</div>
</td>
<td><a onclick=Core2.loadXMLDoc('ajaxrequest.php?aid={$appt->AppointmentID}',['edit'],['detail'],['edit_form_{$appt->AppointmentID}'],"reLoad","hide_all")>Edit</a> | <a onclick=Core2.loadXMLDoc('cancel.php?aid={$appt->AppointmentID}',['delete'],['title_{$appt->AppointmentID}'],['cancel_{$appt->AppointmentID}'],"reLoad","hide_all")>Cancel</a></td>
<td>
{$appt->Location}
</td>
</tr>
EOAPPT;
}
/**
* Close out the Table:
*/
echo <<<EOT
</table>
<iframe name=main width="0" height="0" marginwidth="1" marginheight="1" scrolling="no" border="0" frameborder="0"></iframe>
EOT;
}
require_once('appts/pagebottom.inc');
ob_end_flush();
?>
我建議首先要刪除所有這些換行符以提高讀能力。 – Thilo 2010-11-13 15:23:40
我覺得有這樣的單身人士是愚蠢的。要麼傳遞構造函數的一些初始化參數,要麼'getPendingAppointments()'是一個類方法。 – 2010-11-13 15:24:11
我建議你閱讀我以前問過的問題。 http://stackoverflow.com/questions/4148031/what-is-the-best-practice-to-use-when-using-php-and-html – 2010-11-13 15:25:45