Now: Tutorial for Web and Software Design > PHP > PHP Basic > PHP Content
> Understanding MVC in PHP [Bookmark it]
Understanding MVC in PHP

Understanding MVC in PHP

Presenter.php

This is the foundation for the presentation layer. It uses the factory design pattern to create the presentation layer. FR_Module::$presenter defines which presentation layer to use, which the controller will then create via the factory method. Once the controller has a valid presentation layer, the only thing left to do is to run the common display() function, which presentation classes inherit from FR_Presenter_common.



<?php



  class FR_Presenter

  {

      // {{{ factory($type,FR_Module $module)

      /**

      * factory

      *

      * @author Joe Stump <joe@joestump.net>

      * @access public

      * @param string $type Presentation type (our view)

      * @param mixed $module Our module, which the presenter will display

      * @return mixed PEAR_Error on failure or a valid presenter

      * @static

      */

      static public function factory($type,FR_Module $module)

      {

          $file = FR_BASE_PATH.'/includes/Presenter/'.$type.'.php';

          if (include($file)) {

              $class = 'FR_Presenter_'.$type;

              if (class_exists($class)) {

                  $presenter = new $class($module);

                  if ($presenter instanceof FR_Presenter_common) {

                      return $presenter;

                  }



                  return PEAR::raiseError('Invalid presentation class: '.$type);

              }



              return PEAR::raiseError('Presentation class not found: '.$type);

          }



          return PEAR::raiseError('Presenter file not found: '.$type);

      }

      // }}}

  }



?>

Up Next

So far I have covered why using MVC frameworks make sense and coded the foundation classes. The next article will cover the controller. The third part will cover the view, or presentation layer. The final part of this series will show the creation of the first application built using the framework, the Model.

Example code for this article: framework-0.2.tar.gz

Joe Stump is currently the technology manager for eNotes.com.


Return to the PHP DevCenter.

Prev  [1] [2] [3] [4] [5] [6] 

[Bookmark][Print] [Close][To Top]
  • Prev Article-PHP:

  • Next Article-PHP:
  • Related Materias
    Important Notice for Apach
    Custom-Compiling Apache an
    Apaches eXtended Server Si
    Python and Apache
    Newbies Find Help in OReil
    Apache::CodeRed
    Industrial-Strength Webcas
    AxKit: An XML-Delivery Too
    Module Tour: Embedding Pyt
    Apache Under Windows
    Topics
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Graphic Design Tutorial
     

    Coreldraw Tutorial

      Illustrator Tutorial
      3D Graphics Articles
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial&Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial&Articles
     

    XML Style Tutorial

      AJAX Tutorial
      XML Mobile
    Flash Tutorial&Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial&Articles
     

    Linux Tutorial

      Symbian Tutorial
      MacOS Tutorial