SlideShare a Scribd company logo
1 of 19
Download to read offline
Daniel Cousineau & Chris Weldon
Bar Camp Texas 2008

PHP AND MVC
First Things First

     http://www.google.com/search?hl=en&q=mvc
         Google is wonderful, learn how to use it.
         Or Yahoo
         There are 6,203,493* search engines, use one
     http://www.toosweettobesour.com/
         Slides if anyone wants ‘em
     http://www.chrisweldon.net/



* Possibly incorrect
MVC Is…

 Model, View, Controller
 Object Oriented
   Is communication between Model, View, and
    Controller Objects
 Software Engineering
 Organization
 RAD
   Code reuse!
History
MVC Is Not New!

 Smalltalk-80 (circa 1980)
     MVC first discussed in 1979 by Trygve Mikkjel
      Heyerdahl Reenskaug
   MFC (Document/View)
   Java’s Swing
   QT4 (KDE)
   Apple’s Cocoa (Core Data)
   Notice a trend?
     MVC is perfectly suited for GUI development…
MVC And The Web

 Made popular by Ruby on Rails
   A good number of PHP MVC frameworks are Rails
      inspired
 Wikipedia currently lists about 17 PHP MVC
  frameworks
     CakePHP
     Symfony
     Code Igniter
     Zend Framework
     Make your own (I did!)
Define MVC
Model – View – Controller
Model

 Wikipedia:
   “The domain-specific representation of the
    information that the application operates.”
 Data Storage/Access
   Often Data source backed
     MySQL, MSSQL, Web Service, it doesn’t matter…
   Abstraction, Abstraction, Abstraction!
View

 Wikipedia:
   “Renders the model into a form suitable for
    interaction, typically a user interface element.
    Multiple views can exist for a single model for
    different purposes.”
 HTML Templates
   All formatting related code belongs here
   A Smarty object is a good example
     Any template engine works, however…
   Abstraction, Abstraction, Abstraction!
Controller

 Wikipedia:
   “Processes and responds to events, typically user
    actions, and may invoke changes on the model.”
 A BIG DEAL
   Process user inputs, communicate with Models and
    Views
     The Go-Between
   Much of the application’s core logic
   Utilize the abstraction of before!
     Invoke model, assign values to views
Putting It Together…
http://ash-mvc.org/website/framework/framework.html
As A Framework
Common Traits

 index.php
   Parses the URL
     Often mod_rewrite used:
       /controller/method/arg0/value0/arg1/…/valuen
   Initializes proper controller
   Executes correct method
   Facilitates communication from controller to view
   Signals view to render
Directory Structure

   Outside of web root. More secure! (generally)
   config/
   controllers/
   models/
   views/
     Usually not PHP files
 includes/
     Any extra libraries, e.g. PHPMailer
 framework/
     Framework system files (do not have to reside in
      application)
Helpers and Plug-ins

 Usually common functions used by Views
   E.g. format_phone(), create_calendar(),
    etc.
 Some loaded through index.php, some loaded
  specifically by controller
 Do not allow direct manipulation of models or
  controllers
   Any code requiring access to models should be in the
    controller, not view
Other Utilities…

 Dispatcher classes
   Abstract the location of files
   Abstract creation of links/connections
 Caching classes
   Cache Templates? Output? SQL Queries? Opcode
   Caching individual Templates poses a special problem
     Will dynamism of framework affect caching?
Why MVC?

 Good architectural design
   Code is organized and structure
   Code structure lends itself to an easy to understand
    directory structure
 Easy code maintenance
   Because of abstraction, better strategic positioning of
    code will minimize the hunt for places to change
 Easy to extend and grow
   Modify parent classes, drop in new controller, etc.
Sites Using PHP MVC Frameworks

 CakePHP
   Mozilla Addons
   The Onion’s Online Store
 Symfony
   TED.com
   Yahoo! Bookmarks
 Pretty much everyone.
The Cake Was NOT a Lie!

More Related Content

What's hot

3-TIER ARCHITECTURE IN ASP.NET MVC
3-TIER ARCHITECTURE IN ASP.NET MVC3-TIER ARCHITECTURE IN ASP.NET MVC
3-TIER ARCHITECTURE IN ASP.NET MVC
Mohd Manzoor Ahmed
 
Modularize JavaScript with RequireJS
Modularize JavaScript with RequireJSModularize JavaScript with RequireJS
Modularize JavaScript with RequireJS
Minh Hoang
 
Magento 2.0: Prepare yourself for a new way of module development
Magento 2.0: Prepare yourself for a new way of module developmentMagento 2.0: Prepare yourself for a new way of module development
Magento 2.0: Prepare yourself for a new way of module development
Ivan Chepurnyi
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5
Tuna Tore
 

What's hot (20)

Planbox Backbone MVC
Planbox Backbone MVCPlanbox Backbone MVC
Planbox Backbone MVC
 
Getting started with angular js
Getting started with angular jsGetting started with angular js
Getting started with angular js
 
19servlets
19servlets19servlets
19servlets
 
3-TIER ARCHITECTURE IN ASP.NET MVC
3-TIER ARCHITECTURE IN ASP.NET MVC3-TIER ARCHITECTURE IN ASP.NET MVC
3-TIER ARCHITECTURE IN ASP.NET MVC
 
JSP - Part 2 (Final)
JSP - Part 2 (Final) JSP - Part 2 (Final)
JSP - Part 2 (Final)
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Codegnitorppt
CodegnitorpptCodegnitorppt
Codegnitorppt
 
Jsp chapter 1
Jsp chapter 1Jsp chapter 1
Jsp chapter 1
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Why Django for Web Development
Why Django for Web DevelopmentWhy Django for Web Development
Why Django for Web Development
 
Local storage in Web apps
Local storage in Web appsLocal storage in Web apps
Local storage in Web apps
 
Modularize JavaScript with RequireJS
Modularize JavaScript with RequireJSModularize JavaScript with RequireJS
Modularize JavaScript with RequireJS
 
Implicit object.pptx
Implicit object.pptxImplicit object.pptx
Implicit object.pptx
 
Magento 2.0: Prepare yourself for a new way of module development
Magento 2.0: Prepare yourself for a new way of module developmentMagento 2.0: Prepare yourself for a new way of module development
Magento 2.0: Prepare yourself for a new way of module development
 
Laravel 8 export data as excel file with example
Laravel 8 export data as excel file with exampleLaravel 8 export data as excel file with example
Laravel 8 export data as excel file with example
 
WordPress and Ajax
WordPress and AjaxWordPress and Ajax
WordPress and Ajax
 
Implicit objects advance Java
Implicit objects advance JavaImplicit objects advance Java
Implicit objects advance Java
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
MVC Puree - Approaches to MVC with Umbraco
MVC Puree - Approaches to MVC with UmbracoMVC Puree - Approaches to MVC with Umbraco
MVC Puree - Approaches to MVC with Umbraco
 

Viewers also liked

The Agile Process - Taming Your Process To Work For You
The Agile Process - Taming Your Process To Work For YouThe Agile Process - Taming Your Process To Work For You
The Agile Process - Taming Your Process To Work For You
Nowell Strite
 
Embracing Distributed Version Control
Embracing Distributed Version ControlEmbracing Distributed Version Control
Embracing Distributed Version Control
Nowell Strite
 
RESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkRESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP Framework
Bo-Yi Wu
 

Viewers also liked (8)

Djangocon 09 Presentation - Pluggable Applications
Djangocon 09 Presentation - Pluggable ApplicationsDjangocon 09 Presentation - Pluggable Applications
Djangocon 09 Presentation - Pluggable Applications
 
CodeIgniter - PHP MVC Framework by silicongulf.com
CodeIgniter - PHP MVC Framework by silicongulf.comCodeIgniter - PHP MVC Framework by silicongulf.com
CodeIgniter - PHP MVC Framework by silicongulf.com
 
The Agile Process - Taming Your Process To Work For You
The Agile Process - Taming Your Process To Work For YouThe Agile Process - Taming Your Process To Work For You
The Agile Process - Taming Your Process To Work For You
 
Embracing Distributed Version Control
Embracing Distributed Version ControlEmbracing Distributed Version Control
Embracing Distributed Version Control
 
ACL in CodeIgniter
ACL in CodeIgniterACL in CodeIgniter
ACL in CodeIgniter
 
Introduction To CodeIgniter
Introduction To CodeIgniterIntroduction To CodeIgniter
Introduction To CodeIgniter
 
RESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkRESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP Framework
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 

Similar to PHP & MVC

Introduction to MVC Web Framework with CodeIgniter
Introduction to MVC Web Framework with CodeIgniterIntroduction to MVC Web Framework with CodeIgniter
Introduction to MVC Web Framework with CodeIgniter
Pongsakorn U-chupala
 

Similar to PHP & MVC (20)

Asp.Net Mvc Dev Days09
Asp.Net Mvc Dev Days09Asp.Net Mvc Dev Days09
Asp.Net Mvc Dev Days09
 
Php and-mvc
Php and-mvcPhp and-mvc
Php and-mvc
 
Conquering Gef Part 1: Effectively creating a well designed graphical editor
Conquering Gef Part 1: Effectively creating a well designed graphical editorConquering Gef Part 1: Effectively creating a well designed graphical editor
Conquering Gef Part 1: Effectively creating a well designed graphical editor
 
Mvc
MvcMvc
Mvc
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applications
 
MWLUG 2015 - An Introduction to MVC
MWLUG 2015 - An Introduction to MVCMWLUG 2015 - An Introduction to MVC
MWLUG 2015 - An Introduction to MVC
 
An Introduction To Model  View  Controller In XPages
An Introduction To Model  View  Controller In XPagesAn Introduction To Model  View  Controller In XPages
An Introduction To Model  View  Controller In XPages
 
Dust.js
Dust.jsDust.js
Dust.js
 
Introduction To Code Igniter
Introduction To Code IgniterIntroduction To Code Igniter
Introduction To Code Igniter
 
Introduction to MVC Web Framework with CodeIgniter
Introduction to MVC Web Framework with CodeIgniterIntroduction to MVC Web Framework with CodeIgniter
Introduction to MVC Web Framework with CodeIgniter
 
Coding the UI
Coding the UICoding the UI
Coding the UI
 
Coding Ui
Coding UiCoding Ui
Coding Ui
 
ASP.net MVC CodeCamp Presentation
ASP.net MVC CodeCamp PresentationASP.net MVC CodeCamp Presentation
ASP.net MVC CodeCamp Presentation
 
ASP.NET MVC Zero to Hero
ASP.NET MVC Zero to HeroASP.NET MVC Zero to Hero
ASP.NET MVC Zero to Hero
 
Angular JS, A dive to concepts
Angular JS, A dive to conceptsAngular JS, A dive to concepts
Angular JS, A dive to concepts
 
MVC Framework
MVC FrameworkMVC Framework
MVC Framework
 
Catalyst - refactor large apps with it and have fun!
Catalyst - refactor large apps with it and have fun!Catalyst - refactor large apps with it and have fun!
Catalyst - refactor large apps with it and have fun!
 
Rapid Prototyping With J Query
Rapid Prototyping With J QueryRapid Prototyping With J Query
Rapid Prototyping With J Query
 
Intro to mobile web application development
Intro to mobile web application developmentIntro to mobile web application development
Intro to mobile web application development
 
Applying Domain Driven Design on Asp.net MVC – Part 1: Asp.net MVC
Applying Domain Driven Design on Asp.net MVC – Part 1: Asp.net MVCApplying Domain Driven Design on Asp.net MVC – Part 1: Asp.net MVC
Applying Domain Driven Design on Asp.net MVC – Part 1: Asp.net MVC
 

More from Chris Weldon

SOLID - Not Just a State of Matter, It's Principles for OO Propriety
SOLID - Not Just a State of Matter, It's Principles for OO ProprietySOLID - Not Just a State of Matter, It's Principles for OO Propriety
SOLID - Not Just a State of Matter, It's Principles for OO Propriety
Chris Weldon
 
Unit Testing in SharePoint 2010
Unit Testing in SharePoint 2010Unit Testing in SharePoint 2010
Unit Testing in SharePoint 2010
Chris Weldon
 

More from Chris Weldon (7)

Keat presentation
Keat presentationKeat presentation
Keat presentation
 
REST Easy - Building RESTful Services in Zend Framework
REST Easy - Building RESTful Services in Zend FrameworkREST Easy - Building RESTful Services in Zend Framework
REST Easy - Building RESTful Services in Zend Framework
 
Beyond TDD: Enabling Your Team to Continuously Deliver Software
Beyond TDD: Enabling Your Team to Continuously Deliver SoftwareBeyond TDD: Enabling Your Team to Continuously Deliver Software
Beyond TDD: Enabling Your Team to Continuously Deliver Software
 
SOLID - Not Just a State of Matter, It's Principles for OO Propriety
SOLID - Not Just a State of Matter, It's Principles for OO ProprietySOLID - Not Just a State of Matter, It's Principles for OO Propriety
SOLID - Not Just a State of Matter, It's Principles for OO Propriety
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
 
Unit Testing in SharePoint 2010
Unit Testing in SharePoint 2010Unit Testing in SharePoint 2010
Unit Testing in SharePoint 2010
 
IoC with PHP
IoC with PHPIoC with PHP
IoC with PHP
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

PHP & MVC

  • 1. Daniel Cousineau & Chris Weldon Bar Camp Texas 2008 PHP AND MVC
  • 2. First Things First  http://www.google.com/search?hl=en&q=mvc  Google is wonderful, learn how to use it.  Or Yahoo  There are 6,203,493* search engines, use one  http://www.toosweettobesour.com/  Slides if anyone wants ‘em  http://www.chrisweldon.net/ * Possibly incorrect
  • 3. MVC Is…  Model, View, Controller  Object Oriented  Is communication between Model, View, and Controller Objects  Software Engineering  Organization  RAD  Code reuse!
  • 5. MVC Is Not New!  Smalltalk-80 (circa 1980)  MVC first discussed in 1979 by Trygve Mikkjel Heyerdahl Reenskaug  MFC (Document/View)  Java’s Swing  QT4 (KDE)  Apple’s Cocoa (Core Data)  Notice a trend?  MVC is perfectly suited for GUI development…
  • 6. MVC And The Web  Made popular by Ruby on Rails  A good number of PHP MVC frameworks are Rails inspired  Wikipedia currently lists about 17 PHP MVC frameworks  CakePHP  Symfony  Code Igniter  Zend Framework  Make your own (I did!)
  • 7. Define MVC Model – View – Controller
  • 8. Model  Wikipedia:  “The domain-specific representation of the information that the application operates.”  Data Storage/Access  Often Data source backed  MySQL, MSSQL, Web Service, it doesn’t matter…  Abstraction, Abstraction, Abstraction!
  • 9. View  Wikipedia:  “Renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes.”  HTML Templates  All formatting related code belongs here  A Smarty object is a good example  Any template engine works, however…  Abstraction, Abstraction, Abstraction!
  • 10. Controller  Wikipedia:  “Processes and responds to events, typically user actions, and may invoke changes on the model.”  A BIG DEAL  Process user inputs, communicate with Models and Views  The Go-Between  Much of the application’s core logic  Utilize the abstraction of before!  Invoke model, assign values to views
  • 13. Common Traits  index.php  Parses the URL  Often mod_rewrite used:  /controller/method/arg0/value0/arg1/…/valuen  Initializes proper controller  Executes correct method  Facilitates communication from controller to view  Signals view to render
  • 14. Directory Structure  Outside of web root. More secure! (generally)  config/  controllers/  models/  views/  Usually not PHP files  includes/  Any extra libraries, e.g. PHPMailer  framework/  Framework system files (do not have to reside in application)
  • 15. Helpers and Plug-ins  Usually common functions used by Views  E.g. format_phone(), create_calendar(), etc.  Some loaded through index.php, some loaded specifically by controller  Do not allow direct manipulation of models or controllers  Any code requiring access to models should be in the controller, not view
  • 16. Other Utilities…  Dispatcher classes  Abstract the location of files  Abstract creation of links/connections  Caching classes  Cache Templates? Output? SQL Queries? Opcode  Caching individual Templates poses a special problem  Will dynamism of framework affect caching?
  • 17. Why MVC?  Good architectural design  Code is organized and structure  Code structure lends itself to an easy to understand directory structure  Easy code maintenance  Because of abstraction, better strategic positioning of code will minimize the hunt for places to change  Easy to extend and grow  Modify parent classes, drop in new controller, etc.
  • 18. Sites Using PHP MVC Frameworks  CakePHP  Mozilla Addons  The Onion’s Online Store  Symfony  TED.com  Yahoo! Bookmarks  Pretty much everyone.
  • 19. The Cake Was NOT a Lie!