what is mvc?
TRANSCRIPT
What is MVC?
A Primer in 10 Slides
Dominique Gerald M [email protected]://villageidiotsavant.com
By
Model-View-Controller
an architectural pattern in software engineering
a way of designing and building applications
object-oriented software development
separates application logic from presentation
loose coupling between components
Without MVC
Client
delete.php
update.php
read.php
create.php
database
db=connect(database);
var1=$_POST[data1];var2=$_POST[data2];
db.query(insert into db values var1,var2);
print Success;
http://myapp/create.phphttp://myapp/read.phphttp://myapp/update.phphttp://myapp/delete.php
database
application
presentation
All in one program!
What happens when you...
change the database settings?
change the database design?
change the database?
process more variables?
change the response?
change the look and feel?
How does MVC work?
Client
http://myapp/customer/createhttp://myapp/customer/readhttp://myapp/customer/updatehttp://myapp/customer/delete
customer (controller)
function create() { : :}
function read() { : :}
function update() { : :}
function delete() { : :}
function read($id) {Customer->get($id);$data=Customer->read();::render($data,template.tpl);}
Controller handles application logic
A single controller may have multiple methods
A controller collects all the actions that takes place
Several controllers may comprise an application
How does MVC work?
Client
customer (controller)
function create() { : :}
function read() { : :}
function update() { : :}
function delete() { : :}
function read($id) {Customer->get($id);$data=Customer->read();::render($data,template.tpl);}
Controller invokes models
Controller manipulates model attributes
Controller uses model methods
Models can invoke other models
namecategoryquantity:
read()save():
Customer
http://myapp/customer/createhttp://myapp/customer/readhttp://myapp/customer/updatehttp://myapp/customer/delete
How does MVC work?
Client
customer (controller)
function create() { : :}
function read() { : :}
function update() { : :}
function delete() { : :}
function read($id) {Customer->get($id);$data=Customer->read();::render($data,template.tpl);}
namecategoryquantity:
read()save():
Customer
http://myapp/customer/createhttp://myapp/customer/readhttp://myapp/customer/updatehttp://myapp/customer/delete
$header
$sidebar
for($item in $data) { echo $item;}
Our Customers
: : : :
Charlie BrownLucy Van PeltLinus Van Pelt
Controller combines data with template
Template may perform additional processing
Return combination as HTML
Or we could do it with XML
Client
customer (controller)
function create() { : :}
function read() { : :}
function update() { : :}
function delete() { : :}
function read($id) {Customer->get($id);$data=Customer->read();::render($data,template.tpl);}
namecategoryquantity:
read()save():
Customer
XML request
XML response
$xml->serialize($data)
Whatever...
Java
C / C++
JavaScript
Client does not need to be a web browser
Can be any client that speaks XML
Serialization: conversion of data into bits
With this, we can talk about web services
XML, JSON, YAML, ...
Some MVC web frameworks
Ruby on Rails (www.rubyonrails.org)
CakePHP (www.cakephp.org)
CodeIgniter (www.codeigniter.org)
Yii (www.yiiframework.com)
Django (www.djangoproject.org)
CherryPy (www.cherrypy.org)
Spring MVC (www.springsource.org)
Catalyst (www.catalyst.org)
Mojolicious (www.mojolicio.us)
Frameworks make things easier
BUT
you don't need to use them topractice MVC
License
You are free:to Share: to copy, distribute and transmit the work
to Remix: to adapt the work
Under the following conditions:Attribution: You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).
Share Alike: If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.
With the understanding that:Waiver: Any of the above conditions can be waived if you get permission from the copyright holder.
Public Domain: Where the work or any of its elements is in the public domain under applicable law, that status is in no way affected by the license.
Other Rights: In no way are any of the following rights affected by the license:Your fair dealing or fair use rights, or other applicable copyright exceptions and limitations;
The author's moral rights;
Rights other persons may have either in the work itself or in how the work is used, such as publicity or privacy rights.
Notice: For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to this web page.