PHP
  Home arrow PHP arrow Page 4 - Generating View from MySQL to Simulate...
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Generating View from MySQL to Simulate the Model-View-Controller Schema in PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 14
    2006-08-21

    Table of Contents:
  • Generating View from MySQL to Simulate the Model-View-Controller Schema in PHP
  • The starting point of a brand new MVC schema: defining some MySQL processing classes
  • Setting up the basics for generating disparate views: defining a controller based on MySQL datasets
  • Defining the next link of the chain: creating a model founded on native MySQL data sets
  • Generating distinct views from a single MySQL result set: creating an output generator class
  • Putting the classes to work together: seeing the MVC schema in action

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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


    (Page 4 of 6 )

    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){
            $this->resultController=$resultController;
            $this->controllerOutput=$resultController->getOutput();
            $this->resultObj=$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


       · In the last installment of this series, you'll learn how to implement a basic MVC...
     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT