Whether you choose to use a formal framework or not for your web application, understanding the principles of router - model - view - controller and separateting elements of your code into those areas, and considering the whole to be wrapped in a frameowrk with helper functions / methods makes sense. It means you can re-use code later on. It means that the look and feel are separated from the business logic. It means that you have a common look and behaviour across forms, and common considerations to security too.
From a recent PHP course - an example
[here] and extended to show data validationand exceptions
[here]. Please note that I would normally separate the sections into different files, and be using fucntions like
htmlentities or
htmlspecialchars to protect echoing to sticky fields; you'll see that done in many of our other examples, and it's covered on our
PHP courses (written 2016-02-07, updated 2016-02-08)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
Q915 - Object Orientation and General technical topics - Principles of Model - View - Controller [687] Presentation, Business and Persistence layers in Perl and PHP - (2006-04-17)
[2199] Improving the structure of your early PHP programs - (2009-05-25)
[2612] The Model, View, Controller architecture (MVC) - what, why and how. - (2010-02-01)
[3237] Using functions to keep look and feel apart from calculations - simple C example - (2011-04-09)
[3454] Your PHP website - how to factor and refactor to reduce growing pains - (2011-09-24)
[3624] Why do we need a Model, View, Controller architecture? - (2012-02-25)
[3705] Django Training Courses - UK - (2012-04-23)
[3919] What is a web framework? - (2012-11-10)
[4010] Really Simple Rails - (2013-02-17)
[4066] MVC and Frameworks - a lesson from first principles in PHP - (2013-04-19)
[4114] Teaching CodeIgniter - MVC and PHP - (2013-06-12)
[4320] An example of Model-View-Controller techniques in a Perl / CGI script - (2014-11-20)
[4391] Refactoring Perl applications to give them a rosy future - (2015-01-11)
[4527] Hello Flask world / Python web micro framework - (2015-10-11)
[4691] Real life PHP application using our course training MVC example - (2016-06-05)
H115 - Designing PHP-Based Solutions: Best Practice [123] Short underground journeys and a PHP book - (2004-11-19)
[237] Crossfertilisation, PHP to Python - (2005-03-06)
[261] Putting a form online - (2005-03-29)
[340] Code and code maintainance efficiency - (2005-06-08)
[394] A year on - should we offer certified PHP courses - (2005-07-28)
[426] Robust checking of data entered by users - (2005-08-27)
[563] Merging pictures using PHP and GD - (2006-01-13)
[572] Giving the researcher power over database analysis - (2006-01-22)
[839] Reporting on the 10 largest files or 10 top scores - (2006-08-20)
[896] PHP - good coding practise and sticky radio buttons - (2006-10-17)
[936] Global, Superglobal, Session variables - scope and persistance in PHP - (2006-11-21)
[945] Code quality counts - (2006-11-26)
[1047] Maintainable code - some positive advice - (2007-01-21)
[1052] Learning to write secure, maintainable PHP - (2007-01-25)
[1166] Back button - ensuring order are not submitted twice (PHP) - (2007-04-28)
[1181] Good Programming practise - where to initialise variables - (2007-05-09)
[1182] Painting a masterpiece in PHP - (2007-05-10)
[1194] Drawing hands on a clock face - PHP - (2007-05-19)
[1321] Resetting session based tests in PHP - (2007-08-26)
[1323] Easy handling of errors in PHP - (2007-08-27)
[1381] Using a MySQL database to control mod_rewrite via PHP - (2007-10-06)
[1389] Controlling and labelling Google maps via PHP - (2007-10-13)
[1390] Converting from postal address to latitude / longitude - (2007-10-13)
[1391] Ordnance Survey Grid Reference to Latitude / Longitude - (2007-10-14)
[1482] A story about benchmarking PHP - (2007-12-23)
[1487] Efficient PHP applications - framework and example - (2007-12-28)
[1490] Software to record day to day events and keep an action list - (2007-12-31)
[1533] Short and sweet and sticky - PHP form input - (2008-02-06)
[1623] PHP Techniques - a workshop - (2008-04-26)
[1694] Defensive coding techniques in PHP? - (2008-07-02)
[1794] Refactoring - a PHP demo becomes a production page - (2008-09-12)
[2221] Adding a newsfeed for your users to a multipage PHP application - (2009-06-06)
[2430] Not just a PHP program - a good web application - (2009-09-29)
[2679] How to build a test harness into your PHP - (2010-03-16)
[3539] Separating program and artwork in PHP - easier maintainance, and better for the user - (2011-12-05)
[3813] Injection Attacks - PHP, SQL, HTML, Javascript - and how to neutralise them - (2012-07-22)
[3820] PHP sessions - a best practice teaching example - (2012-07-27)
[3926] Filtering PHP form inputs - three ways, but which should you use? - (2012-11-18)
[4069] Even early on, separate out your program from your HTML! - (2013-04-25)
[4118] We not only teach PHP and Python - we teach good PHP and Python Practice! - (2013-06-18)
[4326] Learning to program - comments, documentation and test code - (2014-11-22)
Some other Articles
What are callbacks? Why use them? An example in PythonIn your room at Well House Manor, Melksham, WiltshireFrom last July (2015)A small teaching program - demonstration of principles onlyUsing an MVC structure - even without a formal frameworkWho was Doctor Beeching and what was his axe?Working out the costs of running a bus service through the dayTransWilts Community Interest Company AGM - 13 Feb 2016, SwindonPeople matter - but there is a tradeoff between different people in thereRail user groups worried about what is happening on the buses