I have a relatively large internal web app I’ve built from scratch using PHP + MySQL over the last 18 months. I started off with a very basic knowledge of PHP and learnt as I went along, so some of my app is messy at best, while the newest parts start to implement design patterns. Mostly though, its been written page by page in a procedural manner with SQL queries, functions and HTML all smashed into one file per page.
I want to move it to an MVC architecture, but despite spending several days researching how to do so, I keep finding conflicting information between blogs or forum posts, which is putting me off refactoring in case I do something wrong and waste my time.
My current layout:
/public (contains index that points to front loader + JS files)
/app (contains front loader file + one procedural file per page)
– /classes (some logic stripped from pages)
– – /sql (individual file per DB table containing methods for each required result set)
– /template (header and footer HTML files with a little PHP mixed in)
– /vendor (third party libraries)
Would I be right in saying that I need to refactor to the following layout:
/public (no change - index points to front loader + JS)
/app (front loader file)
– /controller (front loader points her - file per page which calls model, then presents data to view)
– /model (methods to build data and handle POST data, results returned to controller)
– – /sql (no change - class file per DB table)
– /view (file per page containing HTML and display of data passed by controller)
I’m trying to get my head around the whole MVC concept, but with so many examples and conflicting advice, I’m struggling to piece together what I need to do.
Any help would be much appreciated. Please bear in mind that I’m self-taught in my spare time over the last 18 months, so my coding vocab is relatively simple and knowledge of architecture and patterns is minimal.