Training, Open Source Programming Languages

This is page ... n-PHP.html

Our email: • Phone: 01144 1225 708225

For 2023 - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Larger applications in PHP

I've just finished a two day PHP techniques course - a subject that's tremendous fun to present, and a huge benefit to the delegates, as PHP programs can be written with great beauty, maintainability and expandability (like a Picasso) or they can be an unmaintainable mess (making the dog's dinner look neat!) and this course takes people who already have some PHP experience and helps them learn how to produce Picassos and not dog's dinners!

When you first write a larger application in PHP, it's tempting to provide a separate URL and file for each stage of the application ... but you quickly learn that's NOT the way to go when you discover that program section "x" has to be able to produce form "y" "z" and "a" depending on what the user entered ... and that users will insist on bookmarking intermediate URLs and will appear, Hogwarts wizard like, in mid application if you give them half a chance. Separate files for each stage of the main application is NOT the way to go - you want the whole under a single umbrella!

Our classic "4 layer model" example - (source code, run it) provides a series of stages to an application all under a single parasol - with each step of the process being controlled by a switch statement - the first finishing up from data entered on the previous page, and the second preparing for the next page, whichever one that might be as it depends on what the user had entered.

The four layer model is neat - very neat (and I don't claim to have originated - I give full credit to Rasmus Lerdorf who wrote PHP, and from whom I learned of the technique. But it has always worried me slightly that - as I implement it - ALL of the business logic has been loaded for every page, and that can get a little inefficient as the application moves up the scale to massive.

A chance comment today from a delegate - and I have developed the application forward one more stage. By replacing each switch statement with an include to bring in only the correct finishing code then only the correct preparation code, the technique becomes massively extensible without the need for the main code section to grow either. One of those "bolt of lightening moments" if you like.

Here's the heart of the code ...

// Deal with initialisation
if (! $_SESSION[stage] ) $_SESSION[stage] = 0;
$stage = $_SESSION[stage];
// Finish from the previous stage and prepare for next
// These files would usually be in another directory!
// and one that did NOT have its own URL!
// It would also be a good idea to docement each stage here!
include ("stages.finish$");
include ("stages.prepare$");

You can try it our here. The sample has got sticky fields, data validation, error messages and all the rest in it - and it uses a separate template to keep the look and feel apart from the business logic. The web specific helper routines are also kept in a separate file so they can be shared by other applications. (Am I starting to sound like an advert?)

Source code:
Top level
Web Helpers
Look and feel template
Finish code -from initialise, from user entering his name and department and from each main data entry.
Preparing for next page - for reading name and department, for reading main data entries and for confirming logout.

If you're looking to learn PHP and you feel this is the sort of thing for you, we're running our PHP techniques course every 2 months. If you feel it's likely to be too advanced for you at first, why not come on our PHP Programming course which runs every other month - next start date, 11th August!
(written 2008-07-22, updated 2008-07-23)

Associated topics are indexed as below, or enter for individual articles
H310 - PHP - Putting it all together
  [468] Stand alone PHP programs - (2005-10-18)
  [687] Presentation, Business and Persistence layers in Perl and PHP - (2006-04-17)
  [1754] Upgrade from PHP 4 to PHP 5 - the TRY issue - (2008-08-15)
  [1794] Refactoring - a PHP demo becomes a production page - (2008-09-12)
  [1840] Validating Credit Card Numbers - (2008-10-14)
  [1962] Index Card System for Game Characters in PHP - (2008-12-27)
  [2275] Debugging multipage (session based) PHP applications - (2009-07-09)
  [2635] A PHP example that lets your users edit content without HTML knowledge - (2010-02-14)
  [2931] Syncronise - software, trains, and buses. Please! - (2010-08-22)
  [3454] Your PHP website - how to factor and refactor to reduce growing pains - (2011-09-24)

H302 - PHP - MVC, 4 layer model and templating
  [1634] Kiss and Book - (2008-05-07)
  [1766] Diagrams to show you how - Tomcat, Java, PHP - (2008-08-22)
  [2174] Application design in PHP - multiple step processes - (2009-05-11)
  [2199] Improving the structure of your early PHP programs - (2009-05-25)
  [2221] Adding a newsfeed for your users to a multipage PHP application - (2009-06-06)
  [3539] Separating program and artwork in PHP - easier maintainance, and better for the user - (2011-12-05)
  [3956] Zend / layout of MVC and other files in an example application (PHP) - (2012-12-16)
  [4066] MVC and Frameworks - a lesson from first principles in PHP - (2013-04-19)
  [4114] Teaching CodeIgniter - MVC and PHP - (2013-06-12)
  [4314] PHP training - refreshed modern course, backed up by years of practical experience - (2014-11-16)

Back to
Pictures from South Hampshire
Previous and next
Horse's mouth home
Forward to
Q - Should I use Perl or Python?
Some other Articles
Some Ruby lesser used functions
A special day - last Friday in July
Increasing Java Virtual Machine memory for Tomcat
Q - Should I use Perl or Python?
Larger applications in PHP
Pictures from South Hampshire
Hillier Gardens, Hampshire
Ways to accept credit cards - or not!
As different as night and tyres
Rapid growth leads to server move
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page

This is a page archived from The Horse's Mouth at - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

© WELL HOUSE CONSULTANTS LTD., 2023: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: • WEB: • SKYPE: wellho

PAGE: ... n-PHP.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb