PHP AND MVC
DanielCousineau & ChrisWeldon
Bar CampTexas 2008
First Things First
 http://www.google.com/search?hl=en&q=mvc
 Google is wonderful, learn how to use it.
 OrYahoo
 Ther...
MVC Is…
 Model, View, Controller
 Object Oriented
 Is communication between Model,View, and
Controller Objects
 Softwa...
History
MVC Is Not New!
 Smalltalk-80 (circa 1980)
 MVC first discussed in 1979 byTrygve Mikkjel
Heyerdahl Reenskaug
 MFC (Docu...
MVC And The Web
 Made popular by Ruby on Rails
 A good number of PHP MVC frameworks are Rails
inspired
 Wikipedia curre...
Model –View – Controller
Define MVC
Model
 Wikipedia:
 “The domain-specific representation of the
information that the application operates.”
 Data Storage...
View
 Wikipedia:
 “Renders the model into a form suitable for
interaction, typically a user interface element.
Multiple ...
Controller
 Wikipedia:
 “Processes and responds to events, typically user
actions, and may invoke changes on the model.”...
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/
 Initial...
Directory Structure
 config/
 controllers/
 models/
 views/
 Usually just .html or .tpl files
 includes/
 Any extra...
Helpers and Plug-ins
 Usually common functions used byViews
 E.g. format_phone(), create_calendar(),
etc.
 Some loaded ...
Other Utilities…
 Dispatcher classes
 Abstract the location of files
 Abstract creation of links/connections
 Caching ...
Why MVC?
 Good architectural design
 Code is organized and structure
 Code structure lends itself to an easy to underst...
Sites Using PHP MVC Frameworks
 CakePHP
 Mozilla Addons
 The Onion’s Online Store
 Symfony
 TED.com
 Yahoo! Bookmark...
The Cake Was NOT a Lie!
Upcoming SlideShare
Loading in …5
×

PHP MVC Slides (Powerpoint 2007) - Tower Of Power - Far Too Sweet ...

2,315 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,315
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
81
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • This work is licensed under the Creative Commons Attribution-Share Alike 3.0 United States License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/us/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.

    Presentation given on January 26, 2008
  • http://en.wikipedia.org/wiki/Model-view-controller#Implementations_of_MVC_as_GUI_frameworks
  • http://en.wikipedia.org/wiki/Model-view-controller#PHP
  • Models are where RAD comes in. One should create member functions in the models to do common data tasks (like fetch all posts by user id), since that usually ends up being one of the more time consuming portions of development. If at all possible consider using SQL generation code (e.g. CakePHP’s fetchAll(…)).
  • Invoke models, assign to views
  • PHP MVC Slides (Powerpoint 2007) - Tower Of Power - Far Too Sweet ...

    1. 1. PHP AND MVC DanielCousineau & ChrisWeldon Bar CampTexas 2008
    2. 2. First Things First  http://www.google.com/search?hl=en&q=mvc  Google is wonderful, learn how to use it.  OrYahoo  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. 3. MVC Is…  Model, View, Controller  Object Oriented  Is communication between Model,View, and Controller Objects  Software Engineering  Organization  RAD  Code reuse!
    4. 4. History
    5. 5. MVC Is Not New!  Smalltalk-80 (circa 1980)  MVC first discussed in 1979 byTrygve 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. 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. 7. Model –View – Controller Define MVC
    8. 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. 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.”  HTMLTemplates  All formatting related code belongs here  A Smarty object is a good example  Any template engine works, however…  Abstraction, Abstraction, Abstraction!
    10. 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
    11. 11. Putting It Together… http://ash-mvc.org/website/framework/framework.html
    12. 12. As A Framework
    13. 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. 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. 15. Helpers and Plug-ins  Usually common functions used byViews  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. 16. Other Utilities…  Dispatcher classes  Abstract the location of files  Abstract creation of links/connections  Caching classes  CacheTemplates?Output? SQL Queries? Opcode  Caching individualTemplates poses a special problem  Will dynamism of framework affect caching?
    17. 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. 18. Sites Using PHP MVC Frameworks  CakePHP  Mozilla Addons  The Onion’s Online Store  Symfony  TED.com  Yahoo! Bookmarks  Pretty much everyone.
    19. 19. The Cake Was NOT a Lie!

    ×