Application design in PHP - multiple step processes
When you're putting together a multiple step process in PHP (and that could be anything from a forum to an ordering system), you should bare in mind that each of the program elements will be the 'intermediate' step that takes you from one display to the next ... and that you can't be sure when page "X" has been completed that the next page to be presented really WILL be page "Y" - after all, if the user has failed to enter his password correctly on page "X" you'll want to redisplay it ...
... so here, in principle, is how your code should look. Your application will pick up form data and any existing information from the user's session, then "finish" processing from those inputs. Part of that finishing process will be making the decision as to what page to move onto next, so after finishing from page "X" the code will prepare for page "Y", or page "X" again perhaps. Upon completion of those preparations, the (newly updated) session is saved away, and a template for the new page completed.
Rather than store all the code associated with such a multipage application in one file / logical area, we'll usually split it up. The top level code goes into one file, the "business logic" - code to do the actual application work - into another. A third file contains the "web helpers" - routines which handle the forms, sticky fields, web principles, etc. And a fourth file contains a template - what the web page presented will actually look like.
By splitting the code in this way, it becomes easier to maintain as it's in sensible sized chunks. It also allows for elements to be reused in other areas of the web site / application - for example, a template might be shared right across a site, web helpers across many sites, and the business logic may be used offline as well as on the web. Finally, the division principle allows each section to be independently looked after by experts in that section - you need staff who are masters at each individual trade rather than staff who can dabble a bit in all areas.
If you have heard about MVC ("Model View Controller") parts of what I have written may sound very familiar indeed ... and that is no accident!
We have a sample 'shell' of an application that goes through a multistep process using these principle and you can run it here
. Source code is here (top level)
, here (business logic)
, here (web helpers)
and here (template)
This subject is taught briefly on our learning to program in PHP
and PHP programming
courses, and much more fully covered during our PHP techniques workshop (written 2009-05-11)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articlesH302 - PHP - MVC, 4 layer model and templating 
PHP training - refreshed modern course, backed up by years of practical experience - (2014-11-16) 
Teaching CodeIgniter - MVC and PHP - (2013-06-12) 
MVC and Frameworks - a lesson from first principles in PHP - (2013-04-19) 
Zend / layout of MVC and other files in an example application (PHP) - (2012-12-16) 
Separating program and artwork in PHP - easier maintainance, and better for the user - (2011-12-05) 
Your PHP website - how to factor and refactor to reduce growing pains - (2011-09-24) 
Adding a newsfeed for your users to a multipage PHP application - (2009-06-06) 
Improving the structure of your early PHP programs - (2009-05-25) 
Diagrams to show you how - Tomcat, Java, PHP - (2008-08-22) 
Larger applications in PHP - (2008-07-22) 
Kiss and Book - (2008-05-07)
Some other Articles
Melksham Candidates for Wiltshire Unitary ElectionPreventing forum spam - checks at sign upBalloon Journey in WiltshireMelksham in picturesApplication design in PHP - multiple step processesBasic OO principlesPHP4 v PHP5 - Object Model DifferenceCleaning up redundant objectsDesigning a heirarcy of classes - getting inheritance rightWhen should I use OO techniques?
4672 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 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).