PHP
  Home arrow PHP arrow Page 4 - 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 - Completing the MVC schema: defining a style sheet generator class


    (Page 4 of 5 )

    As I explained in the previous section, the “View” element included within the MVC schema will be represented by a style sheet generator class. This class will be tasked with rendering the previous web page in accordance with the type of style indicated originally by the corresponding web page controller.

    Based on the above concepts, this new class is defined as follows:

    // define 'StyleGenerator' class (view)
    class StyleGenerator{
        private $webPage;
        public function __construct(WebPage $webPage){
            $this->webPage=$webPage;
        }
        public function generateStyle(){
            return str_replace('defaultstyle',$this->webPage-
    >getControllerStyle(),$this->webPage->getPage());
        }
    }

    As you can see, the "StyleGenerator" class listed above also accepts the respective "WebPage" object (remember again that this is the model), and uses the "generateStyle()" method to attach a style sheet to the whole web page. Again, you should notice how the pertinent style is tied to the web document, based on the "decisions" made by the controller class.

    At this stage, I feel pretty satisfied, because I’ve defined the three elements that comprise the complete MVC schema. Therefore, it’s time to put all the classes together and see how different style sheets (called "views") can be dynamically attached to the web document created by the previous "WebPage" class.

    To see how this will be done, you’ll have to read the upcoming section, thus click on the following link.

    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 5 hosted by Hostway
    Stay green...Green IT