SlideShare a Scribd company logo
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 Database backed
     MySQL, MSSQL, Postgresql, 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/arg1/arg2/…/argn/
   Initializes proper controller
   Executes correct method
   Facilitates communication from controller to view
   Signals view to render
Directory Structure

   config/
   controllers/
   models/
   views/
     Usually just .html or .tpl files
 includes/
     Any extra libraries, e.g. PHPMailer
 framework/
     Framework system files
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, only have to change code
    once (usually)
 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 (20)

PPT
Codeigniter simple explanation
Arumugam P
 
PPTX
ASP.NET MVC 5 - EF 6 - VS2015
Hossein Zahed
 
PPT
MVC Architecture in ASP.Net By Nyros Developer
Nyros Technologies
 
PPTX
Asp.net mvc presentation by Nitin Sawant
Nitin S
 
PPT
Code igniter overview
umesh patil
 
PPTX
ASP .NET MVC - best practices
Bohdan Pashkovskyi
 
PPT
ColdFusion framework comparison
VIkas Patel
 
PPSX
C#.net applied OOP - Batch 3
Md. Mahedee Hasan
 
PPT
Asp.net mvc
Naga Harish M
 
ODP
Mvc
abhigad
 
PPTX
Mortal Kombat! ASP.NET MVC vs ASP.NET Webforms – ASP.NET MVC is amazing
Tom Walker
 
PPT
MVC ppt presentation
Bhavin Shah
 
PPTX
Asp.netmvc handson
Prashant Kumar
 
PDF
Structuring web applications with Backbone.js
Diego Cardozo
 
PPTX
ASP .Net MVC 5
Nilachal sethi
 
PPT
ASP.NET MVC Presentation
ivpol
 
PPSX
Oop principles
Md. Mahedee Hasan
 
PDF
Dot net interview questions and asnwers
kavinilavuG
 
PDF
Django
sisibeibei
 
PPTX
Asp.net MVC training session
Hrichi Mohamed
 
Codeigniter simple explanation
Arumugam P
 
ASP.NET MVC 5 - EF 6 - VS2015
Hossein Zahed
 
MVC Architecture in ASP.Net By Nyros Developer
Nyros Technologies
 
Asp.net mvc presentation by Nitin Sawant
Nitin S
 
Code igniter overview
umesh patil
 
ASP .NET MVC - best practices
Bohdan Pashkovskyi
 
ColdFusion framework comparison
VIkas Patel
 
C#.net applied OOP - Batch 3
Md. Mahedee Hasan
 
Asp.net mvc
Naga Harish M
 
Mvc
abhigad
 
Mortal Kombat! ASP.NET MVC vs ASP.NET Webforms – ASP.NET MVC is amazing
Tom Walker
 
MVC ppt presentation
Bhavin Shah
 
Asp.netmvc handson
Prashant Kumar
 
Structuring web applications with Backbone.js
Diego Cardozo
 
ASP .Net MVC 5
Nilachal sethi
 
ASP.NET MVC Presentation
ivpol
 
Oop principles
Md. Mahedee Hasan
 
Dot net interview questions and asnwers
kavinilavuG
 
Django
sisibeibei
 
Asp.net MVC training session
Hrichi Mohamed
 

Viewers also liked (8)

DOC
Application SUNNY
romanucci
 
PPTX
Ng briefing doc 1 june 12
businessdriver-uk
 
PDF
KCM Shifttothesmartzone
Kenjol Capital Management
 
PDF
Elba martinez work group vs work team
Lio Schulze
 
PDF
conic section part 8 of 8
majjisatish
 
DOC
Application ULV
romanucci
 
PPT
Prodhimi akullores
Ardian Kryeziu
 
PPT
Prodhimi pastave
Ardian Kryeziu
 
Application SUNNY
romanucci
 
Ng briefing doc 1 june 12
businessdriver-uk
 
KCM Shifttothesmartzone
Kenjol Capital Management
 
Elba martinez work group vs work team
Lio Schulze
 
conic section part 8 of 8
majjisatish
 
Application ULV
romanucci
 
Prodhimi akullores
Ardian Kryeziu
 
Prodhimi pastave
Ardian Kryeziu
 
Ad

Similar to Php and-mvc (20)

PDF
PHP & MVC
Chris Weldon
 
PDF
Streamlining Your Applications with Web Frameworks
guestf7bc30
 
PPTX
Ps02 cint24 mvc in php
Conestoga Collage
 
PDF
Php framework
cncwebworld
 
PPTX
Php Framework
cncwebworld
 
PDF
MVC in PHP
Vineet Kumar Saini
 
PDF
MVC development company in UK.
Techrishblogger
 
PPTX
MVC & CodeIgniter
Harshit Gupta
 
PPT
Howtobuildyourownframework
hazzaz
 
PPTX
Introduction to MVC Web Framework with CodeIgniter
Pongsakorn U-chupala
 
PDF
Presentation 1 Web--dev
altsav
 
PPTX
MVC Framework
Ashton Feller
 
PDF
IRJET- Lightweight MVC Framework in PHP
IRJET Journal
 
PDF
Developing WordPress Plugins Using the MVC Methodology
Nate Allen
 
PPT
Getting Started with Zend Framework
Juan Antonio
 
PPT
MVC(Model View Controller),Web,Enterprise,Mobile
naral
 
PPTX
4. Web programming MVC.pptx
KrisnaBayu41
 
PPTX
MVC architecture by Mohd.Awais on 18th Aug, 2017
Innovation Studio
 
PPTX
Mvc framework
Dhurham Fahem
 
PHP & MVC
Chris Weldon
 
Streamlining Your Applications with Web Frameworks
guestf7bc30
 
Ps02 cint24 mvc in php
Conestoga Collage
 
Php framework
cncwebworld
 
Php Framework
cncwebworld
 
MVC in PHP
Vineet Kumar Saini
 
MVC development company in UK.
Techrishblogger
 
MVC & CodeIgniter
Harshit Gupta
 
Howtobuildyourownframework
hazzaz
 
Introduction to MVC Web Framework with CodeIgniter
Pongsakorn U-chupala
 
Presentation 1 Web--dev
altsav
 
MVC Framework
Ashton Feller
 
IRJET- Lightweight MVC Framework in PHP
IRJET Journal
 
Developing WordPress Plugins Using the MVC Methodology
Nate Allen
 
Getting Started with Zend Framework
Juan Antonio
 
MVC(Model View Controller),Web,Enterprise,Mobile
naral
 
4. Web programming MVC.pptx
KrisnaBayu41
 
MVC architecture by Mohd.Awais on 18th Aug, 2017
Innovation Studio
 
Mvc framework
Dhurham Fahem
 
Ad

Recently uploaded (20)

PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 

Php and-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 Database backed  MySQL, MSSQL, Postgresql, 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/arg1/arg2/…/argn/  Initializes proper controller  Executes correct method  Facilitates communication from controller to view  Signals view to render
  • 14. Directory Structure  config/  controllers/  models/  views/  Usually just .html or .tpl files  includes/  Any extra libraries, e.g. PHPMailer  framework/  Framework system files
  • 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, only have to change code once (usually)  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!