HomePHP Building a Web Page Controller for Simulating the Model-View-Controller Schema in PHP
Building a Web Page Controller for Simulating the Model-View-Controller Schema in PHP
If youíre one of those PHP developers that want to extend your background in object-based applications, then this series might be quite attractive to you. In these three tutorials (of which this is the second), youíll learn how to simulate a simple Model-View-Controller schema, which can be easily expanded to construct more complex relationships between the different entities, in this case applicable specifically to PHP classes.
Stepping back for a moment to the first tutorial of the series, youíll certainly remember some of the topics that I discussed before. First of all, I went through the basic concepts of how to define and implement an MVC (Model-View-Controller) relationship between classes, by developing a simple and practical example.
As youíll surely recall, this example consisted basically of three separated classes, where each one was originally defined to fit the requirements of a highly-generic MVC schema. In this case, the first class was built as a basic message controller class, then the second one (the model) was constructed to behave like a simple message saving mechanism, and lastly the third one was responsible for generating different views (lowercase, uppercase and reversed, respectively) from an input string passed as an argument to the controller class.
Of course, itís not my intention here to develop a full-featured MVC schema like the one used in Ruby on Rails, but instead provide you with an easy-going introduction to simulating this relationship by the means of some concrete PHP classes. From that point onward, you can expand the model, and develop more sophisticated applications.
Well, assuming that this introduction has refreshed most of the concepts deployed in the previous tutorial, the next step on this journey consists of implementing the MVC schema in the context of a real-world application. We're going to build a web page controller system, which will be capable of creating different style sheets on the fly. In this way it will generate several views from the same model, that is the web document in question.
The experience will be really educational, therefore letís continue learning how to implement a more realistic MVC relationship with PHP. Letís get going!