PHP
  Home arrow PHP arrow Page 4 - 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? 
Google.com  
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 - 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
     

       

    PHP ARTICLES

    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - 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 ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek