HomePHP Completing an MVC-Based Framework's Controller Class
Completing an MVC-Based Framework's Controller Class
In this twelfth part of the series I finish building the controller class that permits you to run CRUD operations against the pertinent ďusersĒ MySQL table. This class uses the model to interface with the data layer, the input class to filter incoming data, and the view class to display output on the browser. This process demonstrates the real functionality of the MVC framework developed in previous tutorials.
Any PHP coder who wants to build thorough, scalable web applications must understand how to implement certain design patterns. This doesnít mean that mastering these patterns will guarantee writing bullet-proof code that scales well in different contexts. But, as the web continues to evolve, design patterns can be of great of help in tackling the challenges imposed by modern web development.
One pattern that has rapidly gained popularity with web developers is called Model-View-Controller. It allows developers to create programs that maintain their business and application logic partially separated from their visual presentation.
It's worth mentioning that the MVC pattern has come into widespread use in frameworks, including those built in PHP. Kohana, CodeIgniter and CakePHP are good examples of frameworks that rely on an MVC layer to leverage all of its functionality. However, you as a PHP programmer may want to learn how to build your own MVC-based framework, or simply have a better understanding of how the existing ones work under the hood.
If thatís the case, then in this series of tutorials youíll find a friendly guide that will walk you through the development of a basic framework in PHP 5. This framework will use a set of reusable components that can be easily glued together under a strict MVC schema.
Now that you know what to expect from this group of tutorials, itís time to review the concepts that were deployed in the last one. In that installment of the series I demonstrated how easy it is to create a MySQL-driven application by using some of the classes of the sample framework built previously, since I defined a basic controller class that could fetch records from a table containing user-related data, as well as create new records and update others.
It's valid to point out, though, that some methods of the controller embedded data retrieved via the model into a few view files. These view files havenít been defined yet. Thus, in the lines to follow Iím going to add to the controller a method that will permit the deletion of database rows.
Ready to learn more on this topic? Then, letís get started!