MVC Architecture, Symfony Framework for PHP Web Apps

Slides:



Advertisements
Similar presentations
{ Model View Controller ASP.NET By Scott Crooks & Maggie Wettergreen.
Advertisements

Design Patterns: Structural Design Patterns
MVC Concepts Basics Model-View-Controller (MVC) Concepts for Web Developers SoftUni Team Technical Trainers Software University
ORM Basics Repository Pattern, Models, Entity Manager Ivan Yonkov Technical Trainer Software University
Doctrine The PHP ORM SoftUni Team Technical Trainers Software University
First Steps in PHP Creating Very Simple PHP Scripts SoftUni Team Technical Trainers Software University
Software Technologies
Web Technology Solutions
Magento Basics Getting started developing for Magento
Introduction to Entity framework
Databases basics Course Introduction SoftUni Team Databases basics
C# Basic Syntax, Visual Studio, Console Input / Output
C# MVC Frameworks – ASP.NET
ASP.NET Essentials SoftUni Team ASP.NET MVC Introduction
C# Basic Syntax, Visual Studio, Console Input / Output
Web API - Introduction AJAX, Spring Data REST SoftUni Team Web API
Introduction to MVC SoftUni Team Introduction to MVC
Deploying Web Application
Setup a PHP + MySQL Development Environment
Thymeleaf and Spring Controllers
WordPress Introduction
PHP MVC Frameworks Course Introduction SoftUni Team Technical Trainers
PHP Fundamentals Course Introduction SoftUni Team Technical Trainers
C# Database Fundamentals with Microsoft SQL Server
JavaScript Applications
Module Development Part 2 Magento 1 Stenik Group Ltd. Martin Grozdanov
Introduction to Entity Framework
Application Architecture, Redux
ASP.NET Integration Testing
ASP.NET Unit Testing Unit Testing Web API SoftUni Team ASP.NET
Classes, Properties, Constructors, Objects, Namespaces
Mocking tools for easier unit testing
JavaScript Applications
State Management Cookies, Sessions SoftUni Team State Management
Browser Routing Design Patterns in JS
EF Code First (Advanced)
PHP MVC Frameworks MVC Fundamentals SoftUni Team Technical Trainers
C# Databases Advanced with Microsoft SQL Server
Spring Filters Spring Interceptors SoftUni Team Spring Interceptors
Software Technologies
EF Relations Object Composition
Entity Framework: Code First
Registration, Login, Thymeleaf
Databases advanced Course Introduction SoftUni Team Databases advanced
C#/Java Web Development Basics
MVC Architecture. Routing
Entity Framework: Relations
Caching Data in ASP.NET MVC
The Right Way Control Flow
ASP.NET Razor Engine SoftUni Team ASP.NET MVC Introduction
AJAX and jQuery AJAX AJAX Concepts, XMLHttpRequest, jQuery AJAX: $.ajax(), $.get(), $.post() jQuery AJAX XMLHttpRequest SoftUni Team Technical Trainers.
ASP.NET MVC Introduction
C#: ASP.NET MVC Overview
Databases Advanced Course Introduction SoftUni Team Databases Advanced
Best Practices and Architecture
C# Web Development Basics
Creating UI elements with Handlebars
Best practices and architecture
Arrays and Multidimensional Arrays
Design & Module Development
Magento Basics part 2 Modules & Themes Stenik Group Ltd. Magento
Extending functionality using Collections
ASP.NET Razor Engine SoftUni Team ASP.NET MVC Introduction
C# Advanced Course Introduction SoftUni Team C# Technical Trainers
Train the Trainers Course
Software Quality Assurance
Version Control Systems
JavaScript Frameworks & AngularJS
JavaScript: ExpressJS Overview
Iterators and Generators
Presentation transcript:

MVC Architecture, Symfony Framework for PHP Web Apps PHP: MVC and Symfony MVC Architecture, Symfony Framework for PHP Web Apps MVC & Symfony SoftUni Team Technical Trainers Software University http://softuni.bg

Contents MVC Concepts Overview, Purpose MVC Pattern Explained Symfony Framework What is Symfony? Annotations Entities Views & Controllers

Have a Question? sli.do #tech-softuni

MVC Overview, Purpose

Model-View-Controller (MVC) Model-View-Controller (MVC) is a software architecture pattern Originally formulated in the late 1970s by Trygve Reenskaug Code reusability and separation of concerns Originally developed for desktop Then adapted for internet applications

Model-View-Controller The MVC Pattern Model-View-Controller

The MVC Pattern Design pattern with three independent components Model (data) Manages data and database logic View (UI) Presentation layer (renders the UI) Controller (logic) Implements the application logic Processes user request, performs an action, updates the data model and invokes a view to render some UI

Model (Data) Set of classes that describes the data we are working with Rules for how the data can be changed and manipulated May contain data validation rules Often encapsulates data stored in a database As well as code used to manipulate the data E.g. Data Access Layer of some kind

View (UI) Defines how the application’s user interface (UI) will be displayed May support master views (layouts) May support sub-views (partial views or controls) May use templates to dynamically generate HTML

Controller (Logic) The core MVC component – holds the logic Process the requests with the help of views and models A set of classes that handles Communication from the user Overall application flow Application-specific logic (business logic) Every controller has one or more "actions"

The MVC Pattern (in Web Apps) HTTP Request Front controller (dispatcher) /Some/Page/ Delegate request User Controller HTTP Response CRUD operations Select view & pass data View (render UI) Model (data) Use data from the model

MVC Workflow (in Web Apps) Incoming request (HTTP request) is routed to a Controller The Controller Processes request and creates a View Model Selects appropriate view to be rendered The View Model is passed to View View transforms the View Model into UI output format (HTML) The response is rendered (HTTP response)

Example: Forum PostController Create($title, $content) Edit($postId) Route (access URL) PostController Create($title, $content) Adds a forum post to the database Edit($postId) Gets post with id $postId and alters the title and content in DB Delete($postId) Finds post by id $postId and deletes it from the DB View($postId) Gets post with id $postId and displays it to the user

Example: Forum (2) UserController Register($username, $passwd) Adds a user to the database Login($username, $passwd) Checks if user exists and if $passwd matches the password in the database (after encryption)

Web MVC Framework for PHP Symfony Web MVC Framework for PHP

What is Symfony? Symfony == popular Web MVC framework for PHP Created by Sensio Labs, open-source, large community Works with many database types (MySQL, SQLite, MSSQL, etc..) Entities managed by Doctrine Defining data models and their properties Scaffolding Code generation tools (less manual typing) Generates data models + DB tables (using Doctrine)

Annotations in Symfony Annotations == comments used by Symfony to modify the method behavior URL that calls the controller action Action name Action Parameters Return type Describes this action

Doctrine Entities (Models in Symfony) Models (data classes) describe the objects, stored in the DB Database table name Class name Field data type Column in the database table Field name

Symfony Entities: Fields Entities have fields and properties like in C# Use annotations for additional functionality Tell the database what column names and types to use Data type Table column name Table column type Table column max length Field name

Symfony Entities: Properties Getters and setters (like in C#) Parameter data type Return data type Return data type Function name Function name Set title Accessing the field Return the object

Symfony Views (Twig Templates) Using the Twig view engine to simplify generating HTML: Twig foreach loop Twig syntax to print data HTML code Twig syntax © Software University Foundation – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.

Symfony Controllers and Actions Action == functions called by accessing a specific URL route Controller action route Action name Action Parameters Return type Controller action

Problem: Simple Calculator Web Application Write a web application, which can calculate the result between two operands Implement addition, subtraction, multiplication and division

Web Application with Symfony Live Exercises in Class (Lab)

Summary MVC Symfony Popular design pattern (architectural model) Runs most of the Web apps Code is organized into Models, Views and Controllers Symfony Web MVC framework for PHP Establishes communication between the user, web application and the database

PHP: MVC and Symfony Overview https://softuni.bg/courses/software-technologies © Software University Foundation – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.

License This course (slides, examples, demos, videos, homework, etc.) is licensed under the "Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International" license © Software University Foundation – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.

Trainings @ Software University Software University Foundation – softuni.org Software University – High-Quality Education, Profession and Job for Software Developers softuni.bg Software University @ Facebook facebook.com/SoftwareUniversity Software University Forums – forum.softuni.bg © Software University Foundation – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.