SlideShare ist ein Scribd-Unternehmen logo
1 von 14
MVC
Model View Controller
MVC purpose?
● An architecture for separating
components of a large code block by
abstracting components of a large code
base into smaller manageable pieces.
● Can be used to structure code of any language
MVC components?
● Model - database management
● View - user interface
● Controller - logic for user requests
Model purpose?
● The model in MVC architecture is responsible
for manipulating the data.
● Structuring data.
● Inserting, deleting, updating

● Never interacts with the view directly
Model example
● The model will define what an acceptable piece of data
should look like.
● Any piece of data not adhering to the model structure
should not be allowed into the database.
Model
Student {
Name: String
Class: String,
Grade: Number,
}
Valid
Student {
Name: “Bob”,
Class: “Math”,
Grade: 80,
}
Not Valid
Student {
ID: 808,
Class:501 ,
Grade: “Pass”,
}
Model using mongoose schema
const mongoose = require(‘mongoose’);
const StudentSchema = new mongoose.Schema({
Name:{ Type: String },
Class:{Type: String},
grade:{Type: Number}
})
Module.exports = mongoose.model(‘Student’, StudentSchema)
View purpose?
● The view is responsible for displaying the
data
● The view never interacts directly with the
model, instead the controller proxys any
data the view may need
View examples
Views provide the user interface in the MVC
architecture and can be simple html or
template engines like EJS and Express-
Handlebars
<%= EJS %>
Controller
● Can be more than one controller in a
project
● Each controller has a specific route or
responsibility with a particular resource
Controller purpose?
● Handles any logic required from user
requests
● The controller acts as a hub for user
requests through the view and retrieval or
modification of the database by way of the
model
Controller answering a request from the
user
//inventory router directs request to applicable
controllers
Router.get('/',inventoryController.getInventory)
Router.post('/', inventoryController.addPart)
● Router has determined controllers responsible for
specific resources to handle requests
const Parts = require("../models/Part");//MODEL
module.exports.getInventory = async (req,res)=>{
//requesting parts from MODEL
const allInventory = await Parts.find()
//VIEW response
res.render('inventory.ejs',{inventory:allInventory})
}
● Controller has ability to query the model for any data
necessary to fulfill the request given by the router
● Once any logic necessary is complete, the view is
provided with any necessary data and then presents
the user with an interface to interact with.
Controller example
student.ejs
MONGODB
/controller/student.js
Const Student =
require(‘./models/student’)
Module.exports.getStudents =
(req,res)=> {
Const allStudents = Student.find();
res.render(students.ejs,{students:allstu
dents})
}
MONGOOSE
./models/student
Server.js
Const studentRoutes=
require(‘./routes/student.js’)
app.use(‘/inventory’,studentRoutes)
/routes/student.js
Const studentCtr=
require(‘./controller/student.js’)
app.get(‘/’, studentCtr.getStudents)

Weitere Àhnliche Inhalte

Ähnlich wie MVC.pptx

MVC
MVCMVC
MVC
akshin
 

Ähnlich wie MVC.pptx (20)

MVC architecture
MVC architectureMVC architecture
MVC architecture
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 
Asp.net mvc
Asp.net mvcAsp.net mvc
Asp.net mvc
 
Model-View-Controller: Tips&Tricks
Model-View-Controller: Tips&TricksModel-View-Controller: Tips&Tricks
Model-View-Controller: Tips&Tricks
 
Mvc
MvcMvc
Mvc
 
MVC
MVCMVC
MVC
 
Sitecore MVC (User Group Conference, May 23rd 2014)
Sitecore MVC (User Group Conference, May 23rd 2014)Sitecore MVC (User Group Conference, May 23rd 2014)
Sitecore MVC (User Group Conference, May 23rd 2014)
 
Asp.Net MVC Intro
Asp.Net MVC IntroAsp.Net MVC Intro
Asp.Net MVC Intro
 
Using a model view-view model architecture for iOS apps
Using a model view-view model architecture for iOS appsUsing a model view-view model architecture for iOS apps
Using a model view-view model architecture for iOS apps
 
Spring Framework-II
Spring Framework-IISpring Framework-II
Spring Framework-II
 
Principles of MVC for PHP Developers
Principles of MVC for PHP DevelopersPrinciples of MVC for PHP Developers
Principles of MVC for PHP Developers
 
Introduction to ASP.NET Core MVC and the MVC Pattern.pptx
Introduction to ASP.NET Core MVC and the MVC Pattern.pptxIntroduction to ASP.NET Core MVC and the MVC Pattern.pptx
Introduction to ASP.NET Core MVC and the MVC Pattern.pptx
 
Technoligent providing custom ASP.NET MVC development services
Technoligent providing custom ASP.NET MVC development servicesTechnoligent providing custom ASP.NET MVC development services
Technoligent providing custom ASP.NET MVC development services
 
ASp.net Mvc 5
ASp.net Mvc 5ASp.net Mvc 5
ASp.net Mvc 5
 
Asp.net c# MVC-5 Training-Day-1 of Day-9
Asp.net c# MVC-5 Training-Day-1 of Day-9Asp.net c# MVC-5 Training-Day-1 of Day-9
Asp.net c# MVC-5 Training-Day-1 of Day-9
 
Asp.net With mvc handson
Asp.net With mvc handsonAsp.net With mvc handson
Asp.net With mvc handson
 
Jinal desai .net
Jinal desai .netJinal desai .net
Jinal desai .net
 
Mvc
MvcMvc
Mvc
 
Asp.net mvc
Asp.net mvcAsp.net mvc
Asp.net mvc
 
angularJs Workshop
angularJs WorkshopangularJs Workshop
angularJs Workshop
 

KĂŒrzlich hochgeladen

Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
Christopher Logan Kennedy
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

KĂŒrzlich hochgeladen (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
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
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
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
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 

MVC.pptx

  • 2. MVC purpose? ● An architecture for separating components of a large code block by abstracting components of a large code base into smaller manageable pieces. ● Can be used to structure code of any language
  • 3. MVC components? ● Model - database management ● View - user interface ● Controller - logic for user requests
  • 4.
  • 5. Model purpose? ● The model in MVC architecture is responsible for manipulating the data. ● Structuring data. ● Inserting, deleting, updating
 ● Never interacts with the view directly
  • 6. Model example ● The model will define what an acceptable piece of data should look like. ● Any piece of data not adhering to the model structure should not be allowed into the database. Model Student { Name: String Class: String, Grade: Number, } Valid Student { Name: “Bob”, Class: “Math”, Grade: 80, } Not Valid Student { ID: 808, Class:501 , Grade: “Pass”, }
  • 7. Model using mongoose schema const mongoose = require(‘mongoose’); const StudentSchema = new mongoose.Schema({ Name:{ Type: String }, Class:{Type: String}, grade:{Type: Number} }) Module.exports = mongoose.model(‘Student’, StudentSchema)
  • 8. View purpose? ● The view is responsible for displaying the data ● The view never interacts directly with the model, instead the controller proxys any data the view may need
  • 9. View examples Views provide the user interface in the MVC architecture and can be simple html or template engines like EJS and Express- Handlebars <%= EJS %>
  • 10. Controller ● Can be more than one controller in a project ● Each controller has a specific route or responsibility with a particular resource
  • 11. Controller purpose? ● Handles any logic required from user requests ● The controller acts as a hub for user requests through the view and retrieval or modification of the database by way of the model
  • 12. Controller answering a request from the user //inventory router directs request to applicable controllers Router.get('/',inventoryController.getInventory) Router.post('/', inventoryController.addPart) ● Router has determined controllers responsible for specific resources to handle requests
  • 13. const Parts = require("../models/Part");//MODEL module.exports.getInventory = async (req,res)=>{ //requesting parts from MODEL const allInventory = await Parts.find() //VIEW response res.render('inventory.ejs',{inventory:allInventory}) } ● Controller has ability to query the model for any data necessary to fulfill the request given by the router ● Once any logic necessary is complete, the view is provided with any necessary data and then presents the user with an interface to interact with. Controller example
  • 14. student.ejs MONGODB /controller/student.js Const Student = require(‘./models/student’) Module.exports.getStudents = (req,res)=> { Const allStudents = Student.find(); res.render(students.ejs,{students:allstu dents}) } MONGOOSE ./models/student Server.js Const studentRoutes= require(‘./routes/student.js’) app.use(‘/inventory’,studentRoutes) /routes/student.js Const studentCtr= require(‘./controller/student.js’) app.get(‘/’, studentCtr.getStudents)