PHP
  Home arrow PHP arrow Page 3 - Generating View from MySQL to Simulate the Model-View-Controller Schema in PHP
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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: starstarstarstarstar / 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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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 - Setting up the basics for generating disparate views: defining a controller based on MySQL datasets
    ( Page 3 of 6 )

    Since I plan to implement an MVC-based schema by using native MySQL result sets, obviously one of the first things I have to do is create a result set controller, which can be directly represented by a PHP class. The first link of this programming chain is the class below, which I called "ResultController," and its definition is as follows:

    // define 'ResultController' (controller)
    class ResultController{
        private $outputRanges=array('xhtml','xml','plain');
        private $output;
        public function __construct($output='xhtml'){
            if(!in_array($output,$this->outputRanges)){
                throw new Exception('Invalid result set output!');
            }
            $this->output=$output;
        }
        public function getOutput(){
            return $this->output;
        }
    } 

    As you can see, this new "ResultController" class is responsible for instructing the corresponding model (keep in mind again that the model is represented by a MySQL result set) about what type of output should be generated. In this case, the class in question will handle three specific kind of views for rendering: PLAIN, XHTML, and XML respectively, thus any other type of output will be refused by this class.

    Like the examples shown in the previous two articles of this series, the above class also exposes an accessor method (the "getOutput()" method), which comes in very handy for retrieving the respective output selected by the controller. Still with me? Good, now that you know how this entirely new controller class looks, let me show you the next class that composes the MVC schema.

    Yes, you're correct! In the next few lines I'll define the model class, which not surprisingly will be represented by a MySQL dataset wrapper. Therefore, keep reading to learn how this class will be coded.



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

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT