Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
Keeping the PHP and the HTML apart

Your Web application includes both presentation and logic, and that logic is further divided into business and display logic. How are you going to manage these various layers? How about keeping each of the logically separate areas in a separate file so that the look and feel can be maintained quite separate from the operations?

Here's a sample application written using this form of separation:

INDEX.PHP4 - THE TOP LAYER

<?
# Separating display, business logic and helpers
include "business.inc";
include "helpers.inc";
include "display.inc";
?>

DISPLAY.INC - THE PRESENTATION LAYER

<html>
<head><title><? title(); ?></title></head>
<body bgcolor=#CCCCFF><h1>Separating the logic</h1>
This is a demonstration of the separation of the "business logic"
from the main code on a PHP page. It's all transparent to the visitor
to your web site, but the page at the actual location called up is simply
a few includes and the real work is is in those:<ul><li>Business Logic
<li>Display Helper logic<li>Display template</ul>
<center><i>Using PHP as it's really intended ;-)</i></center><br><br>

<? result() ; ?>
<br><br>
<? question() ; ?> ...<p>
<form><table>
<tr><td>Let's have you enter an age:</td><td><? input_box("age",4); ?></td></tr>
<tr><td>and a gender</td><td><? input_radio("gender","Male|Female"); ?></td></tr>
<tr><td> and ... </td><td><input type=submit></td></tr>
</table>
</form><br><br>
<? copyright() ; ?>
</body>
</html>

HELPERS.INC - THE HELPERS LAYER

<?
function title() {
        global $title;
        echo $title;
        }
function question() {
        global $formheader;
        echo $formheader;
        }
function copyright() {
        echo "Copyright, Well House Consultants, ".date("Y");
        }
function result () {
        global $result;
        echo "** <u><b>$result</b></u> ** ";
        }
function input_radio($name,$options) {
        foreach (explode("|",$options) as $option) {
                echo "<input type=radio name=$name value=$option> $option<br>";
                }
        }
function input_box($name, $size) {
        echo "<input name=$name size=$size>";
        }
?>

BUSINESS.INC - THE BUSINESS LOGIC LEVEL

<?
$resolved = ($_GET[age] != "");

if ($_GET[age] > 19) {
        $describe = "Adult";
        if ($_GET[gender] == "Male") $describe = "Gentleman";
        if ($_GET[gender] == "Female") $describe = "Lady";
} elseif ($_GET[age] > 12) {
        $describe = "Teenager";
        if ($_GET[gender] == "Male") $describe = "Young Gentleman";
        if ($_GET[gender] == "Female") $describe = "Young Lady";
} elseif ($_GET[age] > 1) {
        $describe = "Child";
        if ($_GET[gender] == "Male") $describe = "Boy";
        if ($_GET[gender] == "Female") $describe = "Girl";
} else {
        $describe = "Baby";
}

if ($resolved) {
        $title = "About our person ....";
        $formheader = "Please enter details for another person";
        $result = "A $_GET[age] year old $_GET[gender] would be described as a '$describe'";
} else {
        $title = "A Welcome page";
        $formheader = "Please enter some information about a person";
        $result = "Your results will appear here";
        }

?>


See also PHP Best Practice - Module

Please note that articles in this section of our web site were current and correct to the best of our ability when published, but by the nature of our business may go out of date quite quickly. The quoting of a price, contract term or any other information in this area of our website is NOT an offer to supply now on those terms - please check back via our main web site

Related Material

PHP - MVC, 4 layer model and templating
  [1634] - ()
  [1716] - ()
  [1766] - ()
  [2174] - ()
  [2199] - ()
  [2221] - ()
  [3454] - ()
  [3539] - ()
  [3956] - ()
  [4066] - ()
  [4114] - ()
  [4314] - ()

Designing PHP-Based Solutions: Best Practice
  [123] - ()
  [237] - ()
  [261] - ()
  [340] - ()
  [394] - ()
  [426] - ()
  [563] - ()
  [572] - ()
  [839] - ()
  [896] - ()
  [936] - ()
  [945] - ()
  [1047] - ()
  [1052] - ()
  [1166] - ()
  [1181] - ()
  [1182] - ()
  [1194] - ()
  [1321] - ()
  [1323] - ()
  [1381] - ()
  [1389] - ()
  [1390] - ()
  [1391] - ()
  [1482] - ()
  [1487] - ()
  [1490] - ()
  [1533] - ()
  [1623] - ()
  [1694] - ()
  [1794] - ()
  [2199] - ()
  [2221] - ()
  [2430] - ()
  [2679] - ()
  [3539] - ()
  [3813] - ()
  [3820] - ()
  [3926] - ()
  [4069] - ()
  [4118] - ()
  [4326] - ()
  [4641] - ()
  [4691] - ()

Web site techniques, utility and visibility
  [23] - ()
  [32] - ()
  [98] - ()
  [109] - ()
  [117] - ()
  [142] - ()
  [165] - ()
  [173] - ()
  [179] - ()
  [182] - ()
  [197] - ()
  [202] - ()
  [222] - ()
  [259] - ()
  [261] - ()
  [268] - ()
  [274] - ()
  [276] - ()
  [278] - ()
  [284] - ()
  [288] - ()
  [311] - ()
  [314] - ()
  [320] - ()
  [322] - ()
  [347] - ()
  [348] - ()
  [369] - ()
  [376] - ()
  [414] - ()
  [492] - ()
  [510] - ()
  [528] - ()
  [533] - ()
  [649] - ()
  [658] - ()
  [681] - ()
  [718] - ()
  [732] - ()
  [757] - ()
  [767] - ()
  [800] - ()
  [893] - ()
  [916] - ()
  [976] - ()
  [994] - ()
  [1015] - ()
  [1029] - ()
  [1055] - ()
  [1104] - ()
  [1177] - ()
  [1184] - ()
  [1186] - ()
  [1198] - ()
  [1207] - ()
  [1212] - ()
  [1237] - ()
  [1297] - ()
  [1437] - ()
  [1494] - ()
  [1505] - ()
  [1506] - ()
  [1513] - ()
  [1534] - ()
  [1541] - ()
  [1554] - ()
  [1610] - ()
  [1630] - ()
  [1634] - ()
  [1653] - ()
  [1711] - ()
  [1747] - ()
  [1756] - ()
  [1793] - ()
  [1797] - ()
  [1833] - ()
  [1856] - ()
  [1888] - ()
  [1955] - ()
  [1961] - ()
  [1970] - ()
  [1982] - ()
  [2056] - ()
  [2065] - ()
  [2225] - ()
  [2332] - ()
  [2333] - ()
  [2334] - ()
  [2335] - ()
  [2336] - ()
  [2337] - ()
  [2338] - ()
  [2339] - ()
  [2340] - ()
  [2340] - ()
  [2341] - ()
  [2389] - ()
  [2410] - ()
  [2519] - ()
  [2532] - ()
  [2552] - ()
  [2569] - ()
  [2668] - ()
  [2981] - ()
  [3022] - ()
  [3087] - ()
  [3149] - ()
  [3197] - ()
  [3367] - ()
  [3426] - ()
  [3491] - ()
  [3532] - ()
  [3554] - ()
  [3563] - ()
  [3589] - ()
  [3623] - ()
  [3734] - ()
  [3744] - ()
  [3745] - ()
  [3776] - ()
  [3896] - ()
  [3974] - ()
  [4001] - ()
  [4076] - ()
  [4115] - ()
  [4136] - ()
  [4239] - ()
  [4376] - ()
  [4401] - ()
  [4474] - ()
  [4492] - ()

resource index - PHP
Solutions centre home page

You'll find shorter technical items at The Horse's Mouth and delegate's questions answered at the Opentalk forum.

At Well House Consultants, we provide training courses on subjects such as Ruby, Lua, Perl, Python, Linux, C, C++, Tcl/Tk, Tomcat, PHP and MySQL. We're asked (and answer) many questions, and answers to those which are of general interest are published in this area of our site.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2021: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/solutions/php-keep ... apart.html • PAGE BUILT: Wed Mar 28 07:47:11 2012 • BUILD SYSTEM: wizard