PHP
  Home arrow PHP arrow Page 2 - Building a Web Page Controller for 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? 
Google.com  
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: starstarstarstarstar / 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:
      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


    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
     

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - 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





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