Using an MVC structure - even without a formal framework
Archive - Originally posted on "The Horse's Mouth" - 2016-02-07 19:16:57 - Graham Ellis
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