HomePHP Creating a Model Class for an MVC-based Framework
Creating a Model Class for an MVC-based Framework
In this ninth part of the series, I add an extensible model class to the framework. This class can be used for running CRUD operations against a selected MySQL database table.
Learning how to implement the Model-View-Controller design pattern is one of those things that you, as a PHP programmer, will have to face sooner or later, especially if you want to follow modern web development approaches.
The good news is that the learning process doesn’t have to be boring. It's possible to get familiar with the key concepts that surround the application of this popular design pattern during the development of a real-world project.
That’s exactly what this group of tutorials attempts to achieve; while reading them, you'll arm yourself with the background required to build a simple, extensible object-oriented framework, which will rely on the structure of the Model-View-Controller design pattern to leverage all of its functionality.
If you've been following the tutorials to this point, you'll see that I've used them to build, step by step, a decent stack of libraries. These comprise the core components of the framework. They include a MySQL driver and a caching class, a basic HTML form helper and a view-handling class.
I left off in the last installment explaining how to build this last component, thus providing the framework with the capability to parse view files in a very straightforward manner. However, handling views is only one-third of the tasks that an MVC framework must perform. It must also be capable of interacting with the database layer through one or more models.
So, in the lines to come I’m going to develop a model class, which will aggregate an instance of the MySQL driver built previously, to handle MySQL database tables through a unified API.
Ready to learn how to build a class like this? Then start reading right now!