Home arrow PHP arrow Page 4 - Generating View from MySQL to Simulate the Model-View-Controller Schema in PHP

Defining the next link of the chain: creating a model founded on native MySQL data sets - PHP

Are you a curious PHP developer, wanting to learn how to simulate a basic Model-View-Controller schema with PHP? Then, look no further, because you’re in the right place. Welcome to the final part of the series “Simulating the Model-View-Controller Schema in PHP.” In three tutorials, this series provides you with a comprehensive introduction, aimed at implementing a MVC-based relationship between PHP objects.

  1. Generating View from MySQL to Simulate the Model-View-Controller Schema in PHP
  2. The starting point of a brand new MVC schema: defining some MySQL processing classes
  3. Setting up the basics for generating disparate views: defining a controller based on MySQL datasets
  4. Defining the next link of the chain: creating a model founded on native MySQL data sets
  5. Generating distinct views from a single MySQL result set: creating an output generator class
  6. Putting the classes to work together: seeing the MVC schema in action
By: Alejandro Gervasio
Rating: starstarstarstarstar / 14
August 21, 2006

print this article



Logically, the next step required to continue defining this MVC-driven relationship rests on creating a concrete model, which will accept the instructions sent by the controller class that you learned in the previous section.

As I mentioned before, again this model should be logically represented by a MySQL result class. In accordance with this concept, below I coded a new class, which I named "MySQLResult." Here it is: 

// define 'MySQLResult' (model)
class MySQLResult{
    private $resultController;
    private $controllerOutput;
    public function __construct(ResultController
$resultController,Result $resultObj){
    public function getControllerOutput(){
        return $this->controllerOutput;
    public function getResultSet(){
        return $this->resultObj->getResultSet();

Closely similar to previous examples shown in the two preceding tutorials, the above "MySQLResult" class accepts the controller object itself as its unique input parameter. Of course, the type of output selected by this controller (or view) is assigned as a new property inside the constructor via the "getOutput()" method.

Additionally, the "MySQLResult" class exposes two extra accessing methods, that is "getControllerOutput()" and "getResultSet()" respectively, which are used to generate the different types of views. Short and understandable, right?

Fine, I believe that the previous class is quite comprehensible, therefore after having defined the corresponding model that belongs to the MVC scheme, it's a good time to see how a View element can be constructed and represented by yet another PHP class. That's exactly the subject of the upcoming section, therefore I suggest you to click on the below link and keep reading.

>>> More PHP Articles          >>> More By Alejandro Gervasio

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: