PHP
  Home arrow PHP arrow An Introduction to Simulating 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

An Introduction to Simulating the Model-View-Controller Schema in PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 17
    2006-08-07


    Table of Contents:
  • An Introduction to Simulating the Model-View-Controller Schema in PHP
  • Defining the MVC schema's first element: constructing a basic PHP controller
  • Extending the MVC relationship: creating a basic model class
  • Completing the MVC schema: defining the view component
  • Assembling the respective elements: implementing the complete MVC schema

  • 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


    An Introduction to Simulating the Model-View-Controller Schema in PHP
    ( Page 1 of 5 )

    Would you like to learn how to simulate an MVC-based system with PHP? If so, you've come to the right place. This is the first article in a three-part series that will show you how to build this schema in PHP by constructing a few classes that represent what is needed.

    Introduction

    When it comes to talking about the good points of a server-side scripting language like PHP, indeed what comes to my mind is its easy learning curve, or its great versatility for interacting with different RDBMS, and of course its excellent implementation of the object model. This last feature is particularly powerful in PHP 5. In this case, I might go on and on listing all the handy features of PHP, but quite possibly you (and me) would get bored quickly, and this wouldn't be an eye-catching subject for an article.

    However, in order to make things more interesting, let me stand on the other side of this terrain for a moment, and speak about some of the most relevant of PHP's drawbacks. It's a fact widely known that its natural ease can lead sometimes to the development of dirty code, or that some of its object-oriented characteristics aren't as thought out as the ones present in other languages like Java or C++. True to form, for the well-being of many PHP developers, most of these limitations can be tackled with a good amount of experience and willpower.

    Now, and specifically speaking, among the features that PHP lacks, there's one that has very popular nowadays: the implementation of a strong Model-View-Controller schema, a concept that has been taken to a superior level with languages like Ruby (and obviously its framework Rails).

    If this doesn't ring any bells to you, by implementing a Model-View-Controller relationship, you can have a programmatic model,  for example a database, which is handled by a set of classes (the controller), all of them being capable of instructing the respective model to generate different outputs (called Views). This paradigm can be as simple as working with three separated entities, or as complex as using multiple databases, generating complete directory structures on the fly, and building up full-featured data grids.

    Well, you may say that such a thing isn't necessary at all for being included in your PHP applications, and certainly you can live happily without it. However, as I said before, it's possible to simulate a MVC schema with PHP, by constructing a few understandable classes that represent a Model, a View, and lastly a Controller.

    However, before I introduce the subject in question, I’d like to clarify one point that I think it’s important to stress: the example that I’m going to develop here is only a basic introduction to the MVC pattern, which means that the corresponding independencies between the sample classes won’t be following a strict model.

    Okay, having clarified the above discussed point, the only thing that I ask from you is a little bit of your willpower, thus you can understand easily how a simple MVC schema can be developed with PHP. Assuming that you're already prepared, let's get started!

     



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

       

    PHP ARTICLES

    - Using Directory Iterators to Build Loader Ap...
    - Using the spl_autoload() Functions to Build ...
    - Working Out of the Object Context to Build L...
    - Using the _autoload() Magic Function to Buil...
    - The Destruct Magic Function in PHP 5
    - The Autoload Magic Function in PHP 5
    - Developing a Recursive Loading Class for Loa...
    - The Sleep and Wakeup Magic Functions in PHP 5
    - Using the Clone Magic Function in PHP 5
    - Including Files Recursively with Loader Appl...
    - The Call Magic Function in PHP 5
    - Designing a Captcha System with PHP and MySQL
    - Using Static Methods to Build Loader Apps in...
    - The Isset and Unset Magic Functions in PHP 5
    - Advanced PHP Form Input Validation to Check ...





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