PHP
  Home arrow PHP arrow Page 2 - Building a Web Page Controller for Sim...
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 
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

Building a Web Page Controller for 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 / 11
    2006-08-14

    Table of Contents:
  • Building a Web Page Controller for Simulating the Model-View-Controller Schema in PHP
  • Creating the first component of the schema: defining a web page controller class
  • Creating a real-world model: defining a web page generator class
  • Completing the MVC schema: defining a style sheet generator class
  • Putting the MVC schema to work: generating style sheets on the fly

  • 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


    Building a Web Page Controller for Simulating the Model-View-Controller Schema in PHP - Creating the first component of the schema: defining a web page controller class


    (Page 2 of 5 )

    Since I plan to follow a logical sequence for building this new MVC schema with PHP, first I’ll define the controller itself, which in this case is represented by a simple web page controller class.

    As you’ll learn later on, this class will be responsible for instructing the model about what style sheet should be used when rendering the corresponding web document. But, in fact, I’m getting ahead of myself, so now pay attention to the definition of this controller class, which is listed below:

    // define 'PageController' class (controller)
    class PageController{
        private $styleRanges=array('styles1','styles2','styles3');
        private $style;
        public function __construct($style='styles1'){
            if(!in_array($style,$this->styleRanges)){
                throw new Exception('Invalid web page style!');
            }
            $this->style=$style;
        }
        // return type of view
        public function getStyle(){
            return $this->style;
        }
    }

    As shown above, the “PageController” class accepts the name of a specific style sheet as the only incoming argument, in order to assign it as a property inside the respective constructor. Of course, it’s easy to guess that this style will be used by the controller class to instruct the web document on what style sheet to display, by using the “getStyle()” method defined above.

    Still with me? Fine, now that you know how the web page controller class looks, let me walk one step further and show you the second link of the MVC schema. In the next section of the article, you’ll see how to build a simple –- yet efficient -- web page generator class, which will represent the model element inside the MVC relationship that I’m currently developing.

    To learn more about how this class will be defined, please click on the link that appears below and keep on reading.

    More PHP Articles
    More By Alejandro Gervasio


       · The second article of this series demonstrates how to use the MVC pattern, in order...
       · It seems that you don't understand the MVC pattern well.
       · Thank you for commenting on this PHP article. I do accept your criticism, but the...
       · I wish MVC was that simple. It is not though. But I still think your article is...
       · Thank you for the comments on my PHP article, and I'm glad to know it was useful...
     

       

    PHP ARTICLES

    - Authentication Scripts for a User Management...
    - Utilizing the Use Keyword for Namespaces in ...
    - Building a User Management Application
    - 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





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