SlideShare a Scribd company logo
1 of 17
Download to read offline
Principles of MVC For
PHP Developers
View PHP & MYSQL Course at: http://www.edureka.co/php-mysql
For more details please contact us:
US : 1800 275 9730 (toll free)
INDIA : +91 88808 62004
Email Us : sales@edureka.co
For Queries:
Post on Twitter @edurekaIN: #askEdureka
Post on Facebook /edurekaIN
Slide 2 www.edureka.co/php-mysql
Objectives
At the end of this module, you will be able to understand:
 Challenges Faced when Designing an Application Without Framework
 MCV Design Patterns
 Logic Behind MVC
 DRY and Convention Over Configuration
 MVC Benefits
 Demo on MVC in PHP
Slide 3 www.edureka.co/php-mysql
Challenges Faced when Designing an Application without a Framework
 Complexity in Coding in straight PHP  Everything must be tested; which is difficult
 Difficult to re-use code
 Hard code everything from scratch
 Teamwork challenges - parallel
programming cannot be done
efficiently
Slide 4 www.edureka.co/php-mysql
 Leads to disorganization  Change one thing , break another
Challenges Faced when Designing an Application without a Framework
Slide 5 www.edureka.co/php-mysql
The Solution is to use Design Patterns
Design Patterns is the way to organize a program
in a proper manner
One such design pattern is MVC
Slide 6 www.edureka.co/php-mysql
Introduction – What is MVC
MVC Introduction
MVC is acronym for Model-View-Controller
A software design pattern for developing web and desktop applications
In simple words, a better way of separating the logic of your application from
the display.
Slide 7 www.edureka.co/php-mysql
 Originally described in terms of a design pattern for use with Smalltalk by Trygve Reenskaug in 1979.
 His paper was published under the title "Applications Programming in Smalltalk-80: How to use Model-View-
Controller", and paved the groundwork for most future MVC implementations.
 MVC design pattern is used to separate an application’s data, business logic, and presentation; doing so facilitates
the creation of more maintainable, reusable, and testable code.
• Model - Data Layer
• View - User Interface Layer
• Controller - Interacts with the Model
MVC Introduction
Slide 8 www.edureka.co/php-mysql
MVC - Illustration
Web
Browser/Client
HTTP Request
HTTP Response
CONTROLLER MODEL
VIEW
Data object
Request
Data Objects
Response
Render dataEvents
(GET/POST)
Handled by Framework
(Hidden from user)
Database
Database
Request
Raw Data
Response
MVC Container
Website User
http://www.mywebsite.com
Slide 9 www.edureka.co/php-mysql
Model
Data access routines and some business logic can be defined in the model.
Model is responsible for providing the data from the database and saving the data
into the data store.
Models are active representations of database tables: they can connect to your
database, query it (if instructed to do so by a controller) and save data to the
database.
No interaction between models and views: all the logic is handled by controllers.
MVC - Data Layer
Slide 10 www.edureka.co/php-mysql
View
Views define exactly what is presented to the user.
It collects data from the user and gives it to controller and controller invokes the
required model.
Controllers pass data to each view to render in some format.
Views can be described as template files that present their content to the user:
variables, arrays and objects that are used in views are registered through a
controller.
Views should not contain complex business logic; only the elementary control
structures necessary to perform particular operations, such as the iteration of
collected data through a foreach construct, should be contained within a view.
MVC - User Interface Layer
Slide 11 www.edureka.co/php-mysql
Controller
Controllers bind the whole pattern together.
Controller is intermediary between View and Model.
Controllers contain the logic of your application.
Each controller can offer different functionality; controllers retrieve and modify data by
accessing database tables through models; and they register variables and objects, which
can be used in views.
Once request is received from client it executes the appropriate business logic from the
model, decide which view to display based on the user's request and other factors, pass
along the data that each view will need, or hand off control to another controller entirely.
MVC - Interacting With Model
Slide 12 www.edureka.co/php-mysql
DRY
 DRY just means "Don't Repeat Yourself". Make sure that when you write code, you only write it one time.
 The DRY principle is stated as "Every piece of knowledge must have a single, unambiguous, authoritative
representation within a system."
Reference: https://maurits.wordpress.com
Slide 13 www.edureka.co/php-mysql
Convention Over Configuration
 Convention over configuration (also known as coding by convention) is a software design paradigm which seeks
to :
 For example, if there is a class Sale in the model, the corresponding table in the database is called "sales" by default.
It is only if one deviates from this convention, such as calling the table "product sales", that one needs to write code
regarding these names.
Not losing
flexibility
Decrease
number of
decisions on
developers
Gain
Simplicity
Slide 14 www.edureka.co/php-mysql
MVC Benefits
Slide 15 www.edureka.co/php-mysql
Demo on
MVC in PHP
Questions
Slide 16 www.edureka.co/php-mysqlTwitter @edurekaIN, Facebook /edurekaIN, use #AskEdureka for Questions
Principles of MVC for PHP Developers

More Related Content

What's hot

ASP .NET MVC
ASP .NET MVC ASP .NET MVC
ASP .NET MVC
eldorina
 
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
 
ColdFusion framework comparison
ColdFusion framework comparisonColdFusion framework comparison
ColdFusion framework comparison
VIkas Patel
 

What's hot (20)

ASP.NET MVC 3
ASP.NET MVC 3ASP.NET MVC 3
ASP.NET MVC 3
 
ASP .NET MVC
ASP .NET MVC ASP .NET MVC
ASP .NET MVC
 
MSDN - ASP.NET MVC
MSDN - ASP.NET MVCMSDN - ASP.NET MVC
MSDN - ASP.NET MVC
 
MVC ppt presentation
MVC ppt presentationMVC ppt presentation
MVC ppt presentation
 
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
 
Mvc4
Mvc4Mvc4
Mvc4
 
What's new in asp.net mvc 4
What's new in asp.net mvc 4What's new in asp.net mvc 4
What's new in asp.net mvc 4
 
ASP .NET MVC Introduction & Guidelines
ASP .NET MVC Introduction & Guidelines  ASP .NET MVC Introduction & Guidelines
ASP .NET MVC Introduction & Guidelines
 
ASP .NET MVC - best practices
ASP .NET MVC - best practicesASP .NET MVC - best practices
ASP .NET MVC - best practices
 
Mvc architecture
Mvc architectureMvc architecture
Mvc architecture
 
Asp.net mvc presentation by Nitin Sawant
Asp.net mvc presentation by Nitin SawantAsp.net mvc presentation by Nitin Sawant
Asp.net mvc presentation by Nitin Sawant
 
Getting started with MVC 5 and Visual Studio 2013
Getting started with MVC 5 and Visual Studio 2013Getting started with MVC 5 and Visual Studio 2013
Getting started with MVC 5 and Visual Studio 2013
 
ASP.NET MVC for Begineers
ASP.NET MVC for BegineersASP.NET MVC for Begineers
ASP.NET MVC for Begineers
 
Asp.net MVC training session
Asp.net MVC training sessionAsp.net MVC training session
Asp.net MVC training session
 
ColdFusion framework comparison
ColdFusion framework comparisonColdFusion framework comparison
ColdFusion framework comparison
 
AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get started
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
Developing large scale JavaScript applications
Developing large scale JavaScript applicationsDeveloping large scale JavaScript applications
Developing large scale JavaScript applications
 

Viewers also liked

2 08 client-server architecture
2 08 client-server architecture2 08 client-server architecture
2 08 client-server architecture
jit_123
 
Client Server Architecture
Client Server ArchitectureClient Server Architecture
Client Server Architecture
suks_87
 

Viewers also liked (20)

Scrum sprint structure workshop by Nermina Durmić
Scrum sprint structure workshop by Nermina DurmićScrum sprint structure workshop by Nermina Durmić
Scrum sprint structure workshop by Nermina Durmić
 
Css naming conventions
Css naming conventionsCss naming conventions
Css naming conventions
 
Scrum In 15 Minutes
Scrum In 15 MinutesScrum In 15 Minutes
Scrum In 15 Minutes
 
PHP Frameworks and CodeIgniter
PHP Frameworks and CodeIgniterPHP Frameworks and CodeIgniter
PHP Frameworks and CodeIgniter
 
Don't Fear the Regex - Northeast PHP 2015
Don't Fear the Regex - Northeast PHP 2015Don't Fear the Regex - Northeast PHP 2015
Don't Fear the Regex - Northeast PHP 2015
 
PHP Templating Systems
PHP Templating SystemsPHP Templating Systems
PHP Templating Systems
 
Introduction to PHP H/MVC Frameworks by www.silicongulf.com
Introduction to PHP H/MVC Frameworks by www.silicongulf.comIntroduction to PHP H/MVC Frameworks by www.silicongulf.com
Introduction to PHP H/MVC Frameworks by www.silicongulf.com
 
Grokking regex
Grokking regexGrokking regex
Grokking regex
 
/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/i
/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/i/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/i
/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/i
 
PHP Framework
PHP FrameworkPHP Framework
PHP Framework
 
Parsing JSON with a single regex
Parsing JSON with a single regexParsing JSON with a single regex
Parsing JSON with a single regex
 
Regular Expression (Regex) Fundamentals
Regular Expression (Regex) FundamentalsRegular Expression (Regex) Fundamentals
Regular Expression (Regex) Fundamentals
 
Php 2 - Approfondissement MySQL, PDO et MVC
Php 2 - Approfondissement MySQL, PDO et MVCPhp 2 - Approfondissement MySQL, PDO et MVC
Php 2 - Approfondissement MySQL, PDO et MVC
 
Hospital information systems - HIS
Hospital information systems - HISHospital information systems - HIS
Hospital information systems - HIS
 
Why MVC?
Why MVC?Why MVC?
Why MVC?
 
2 08 client-server architecture
2 08 client-server architecture2 08 client-server architecture
2 08 client-server architecture
 
Client server architecture
Client server architectureClient server architecture
Client server architecture
 
Introduction to php basics
Introduction to php   basicsIntroduction to php   basics
Introduction to php basics
 
Client Server Architecture
Client Server ArchitectureClient Server Architecture
Client Server Architecture
 
Client server architecture
Client server architectureClient server architecture
Client server architecture
 

Similar to Principles of MVC for PHP Developers

Similar to Principles of MVC for PHP Developers (20)

Principles of MVC for Rails Developers
Principles of MVC for Rails DevelopersPrinciples of MVC for Rails Developers
Principles of MVC for Rails Developers
 
Mvc
MvcMvc
Mvc
 
Building Restful Web App Rapidly in CakePHP
Building Restful Web App Rapidly in CakePHPBuilding Restful Web App Rapidly in CakePHP
Building Restful Web App Rapidly in CakePHP
 
IntroductionToMVC
IntroductionToMVCIntroductionToMVC
IntroductionToMVC
 
Building Web Application Using Spring Framework
Building Web Application Using Spring FrameworkBuilding Web Application Using Spring Framework
Building Web Application Using Spring Framework
 
Ppt of Basic MVC Structure
Ppt of Basic MVC StructurePpt of Basic MVC Structure
Ppt of Basic MVC Structure
 
Rapid Development With CakePHP
Rapid Development With CakePHPRapid Development With CakePHP
Rapid Development With CakePHP
 
Avigma Tech LLC- Why the MVC pattern so popular?
Avigma Tech LLC- Why the MVC pattern so popular?Avigma Tech LLC- Why the MVC pattern so popular?
Avigma Tech LLC- Why the MVC pattern so popular?
 
Introduction to mvc architecture
Introduction to mvc architectureIntroduction to mvc architecture
Introduction to mvc architecture
 
IRJET- Lightweight MVC Framework in PHP
IRJET- Lightweight MVC Framework in PHPIRJET- Lightweight MVC Framework in PHP
IRJET- Lightweight MVC Framework in PHP
 
Intro ASP MVC
Intro ASP MVCIntro ASP MVC
Intro ASP MVC
 
Spring Framework-II
Spring Framework-IISpring Framework-II
Spring Framework-II
 
MVC & backbone.js
MVC & backbone.jsMVC & backbone.js
MVC & backbone.js
 
MVC(Model View Controller),Web,Enterprise,Mobile
MVC(Model View Controller),Web,Enterprise,MobileMVC(Model View Controller),Web,Enterprise,Mobile
MVC(Model View Controller),Web,Enterprise,Mobile
 
Top 40 MVC Interview Questions and Answers | Edureka
Top 40 MVC Interview Questions and Answers | EdurekaTop 40 MVC Interview Questions and Answers | Edureka
Top 40 MVC Interview Questions and Answers | Edureka
 
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
 
MVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVCMVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVC
 
Php Framework
Php FrameworkPhp Framework
Php Framework
 
Php framework
Php frameworkPhp framework
Php framework
 
Mvc Architecture in a web based application
Mvc Architecture in a web based applicationMvc Architecture in a web based application
Mvc Architecture in a web based application
 

More from Edureka!

More from Edureka! (20)

What to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaWhat to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | Edureka
 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | Edureka
 
Top 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaTop 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | Edureka
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | Edureka
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | Edureka
 
Top Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaTop Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | Edureka
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | Edureka
 
How to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaHow to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| Edureka
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | Edureka
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | Edureka
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | Edureka
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | Edureka
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | Edureka
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | Edureka
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | Edureka
 
Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaA star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | Edureka
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | Edureka
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

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
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
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...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
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
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
"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 ...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 

Principles of MVC for PHP Developers

  • 1. Principles of MVC For PHP Developers View PHP & MYSQL Course at: http://www.edureka.co/php-mysql For more details please contact us: US : 1800 275 9730 (toll free) INDIA : +91 88808 62004 Email Us : sales@edureka.co For Queries: Post on Twitter @edurekaIN: #askEdureka Post on Facebook /edurekaIN
  • 2. Slide 2 www.edureka.co/php-mysql Objectives At the end of this module, you will be able to understand:  Challenges Faced when Designing an Application Without Framework  MCV Design Patterns  Logic Behind MVC  DRY and Convention Over Configuration  MVC Benefits  Demo on MVC in PHP
  • 3. Slide 3 www.edureka.co/php-mysql Challenges Faced when Designing an Application without a Framework  Complexity in Coding in straight PHP  Everything must be tested; which is difficult  Difficult to re-use code  Hard code everything from scratch  Teamwork challenges - parallel programming cannot be done efficiently
  • 4. Slide 4 www.edureka.co/php-mysql  Leads to disorganization  Change one thing , break another Challenges Faced when Designing an Application without a Framework
  • 5. Slide 5 www.edureka.co/php-mysql The Solution is to use Design Patterns Design Patterns is the way to organize a program in a proper manner One such design pattern is MVC
  • 6. Slide 6 www.edureka.co/php-mysql Introduction – What is MVC MVC Introduction MVC is acronym for Model-View-Controller A software design pattern for developing web and desktop applications In simple words, a better way of separating the logic of your application from the display.
  • 7. Slide 7 www.edureka.co/php-mysql  Originally described in terms of a design pattern for use with Smalltalk by Trygve Reenskaug in 1979.  His paper was published under the title "Applications Programming in Smalltalk-80: How to use Model-View- Controller", and paved the groundwork for most future MVC implementations.  MVC design pattern is used to separate an application’s data, business logic, and presentation; doing so facilitates the creation of more maintainable, reusable, and testable code. • Model - Data Layer • View - User Interface Layer • Controller - Interacts with the Model MVC Introduction
  • 8. Slide 8 www.edureka.co/php-mysql MVC - Illustration Web Browser/Client HTTP Request HTTP Response CONTROLLER MODEL VIEW Data object Request Data Objects Response Render dataEvents (GET/POST) Handled by Framework (Hidden from user) Database Database Request Raw Data Response MVC Container Website User http://www.mywebsite.com
  • 9. Slide 9 www.edureka.co/php-mysql Model Data access routines and some business logic can be defined in the model. Model is responsible for providing the data from the database and saving the data into the data store. Models are active representations of database tables: they can connect to your database, query it (if instructed to do so by a controller) and save data to the database. No interaction between models and views: all the logic is handled by controllers. MVC - Data Layer
  • 10. Slide 10 www.edureka.co/php-mysql View Views define exactly what is presented to the user. It collects data from the user and gives it to controller and controller invokes the required model. Controllers pass data to each view to render in some format. Views can be described as template files that present their content to the user: variables, arrays and objects that are used in views are registered through a controller. Views should not contain complex business logic; only the elementary control structures necessary to perform particular operations, such as the iteration of collected data through a foreach construct, should be contained within a view. MVC - User Interface Layer
  • 11. Slide 11 www.edureka.co/php-mysql Controller Controllers bind the whole pattern together. Controller is intermediary between View and Model. Controllers contain the logic of your application. Each controller can offer different functionality; controllers retrieve and modify data by accessing database tables through models; and they register variables and objects, which can be used in views. Once request is received from client it executes the appropriate business logic from the model, decide which view to display based on the user's request and other factors, pass along the data that each view will need, or hand off control to another controller entirely. MVC - Interacting With Model
  • 12. Slide 12 www.edureka.co/php-mysql DRY  DRY just means "Don't Repeat Yourself". Make sure that when you write code, you only write it one time.  The DRY principle is stated as "Every piece of knowledge must have a single, unambiguous, authoritative representation within a system." Reference: https://maurits.wordpress.com
  • 13. Slide 13 www.edureka.co/php-mysql Convention Over Configuration  Convention over configuration (also known as coding by convention) is a software design paradigm which seeks to :  For example, if there is a class Sale in the model, the corresponding table in the database is called "sales" by default. It is only if one deviates from this convention, such as calling the table "product sales", that one needs to write code regarding these names. Not losing flexibility Decrease number of decisions on developers Gain Simplicity
  • 16. Questions Slide 16 www.edureka.co/php-mysqlTwitter @edurekaIN, Facebook /edurekaIN, use #AskEdureka for Questions