PHP
  Home arrow PHP arrow An Introduction to Simulating the Mode...
Dev Shed Forums 
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 
Moblin 
JMSL Numerical Library 
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: 4 stars4 stars4 stars4 stars4 stars / 16
    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:
      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


    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


       · The first article of this series shows in a friendly fashion how to simulate the...
       · Hi,Personally, I think it's strange to have the model know anything about the...
       · This article make a serious error in having the Model dependent on the Controller....
       · Hi,Thank you for commenting on this PHP article. Concerning your opinion, as I...
       · Thank you for your comments on this tutorial. As I posted above, this was an...
       · perhaps a tutorial on a full system broken into several articles might be a good...
       · Hello Jon,Thank you for posting your comments on my PHP article. I appreciate...
       · After all of this constructive feedback concerning the controller it might be a good...
       · Hi Jon again,I introduced a correction into the article, as you...
     

       

    PHP ARTICLES

    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter
    - Building Your Own System Tray Application Us...
    - Structuring Your Projects for Web Applicatio...
    - Inserting, Updating and Deleting Database Ro...
    - Building Your Own Desktop Notepad Applicatio...
    - Web Application Security Overview
    - Working with the Active Record Class in Code...
    - Generate PDF Documents with PHP on the Windo...
    - Sending Email with PHP Networking
    - Performing Strict Validation with the Code I...
    - The preg_replace_callback() function in PHP
    - PHP Networking
    - Validating Web Forms with the Code Igniter P...





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