Introduction to MVC PHP Web Development Ivan Yonkov Training Manager

Slides:



Advertisements
Similar presentations
Introduction to MVC Adding a View Page NTPCUG Tom Perkins, Ph.D.
Advertisements

Ruby on Rails Model of MVC. Model-View-Controller Paradigm A way of organizing a software system Benefits: Isolation of business logic from the user interface.
REST Introduction. REST Concept REST is between Resource R epresentational S tate T ransfer between Resource A style of software architecture A Virtual.
INTRODUCTION The Group WEB BROWSER FOR RELATION Goals.
Week 2 IBS 685. Static Page Architecture The user requests the page by typing a URL in a browser The Browser requests the page from the Web Server The.
PHP Scripts HTML Forms Two-tier Software Architecture PHP Tools.
Multiple Tiers in Action
PHP Scripts HTML Forms Two-tier Software Architecture PHP Tools.
Overview of Framework by Ahamed Rifaudeen A. page - i Steps before entering into the Framework?  Basic knowledge of object-oriented programming (OOP)
UNIT-V The MVC architecture and Struts Framework.
Ivan Marković MSP Lead Software Developer at SPAN d.o.o. m.
SIMPLE ROUTER The slide made by Salim Malakouti. Next we will create the Router  What do I we mean by a router?  Routers work similar to a map. It receives.
Internet Basics Dr. Norm Friesen June 22, Questions What is the Internet? What is the Web? How are they different? How do they work? How do they.
Standalone Java Application vs. Java Web Application
Apache and... Virtual Hosts ---- aliases mod_rewrite ---- htaccess AFNOG 11 Kigali, Rwanda May 2010 Dorcas Muthoni Courtesy: Hervey Allen.
Pemrograman Web MVC Programming and Design Pattern in PHP 5.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
MVC Advanced & Reflection Reflection, Parsing Dynamic Data, Asynchronous Requests SoftUni Team Technical Trainers Software University
PHP - Basic Language Constructs CSCI 297 Scripting Languages - Day Two.
CHAPTER 9 PHP AND MYSQL. A POSSIBLE SITE CONFIGURATION Application Folder index.php includes (folder)header.phpfooter.phpstyle.cssmodel (folder)mysqli_connect.php.
First Indico Workshop WEB FRAMEWORKS Adrian Mönnich May 2013 CERN.
MVC Concepts Basics Model-View-Controller (MVC) Concepts for Web Developers SoftUni Team Technical Trainers Software University
Dynamic web content HTTP and HTML: Berners-Lee’s Basics.
CIS166AE : PHP Web Scripting Rob Loy. Tonight’s Agenda Housekeeping items Housekeeping items PHP basics PHP basics Student connection to server Student.
1 Apache and... Virtual Hosts ---- aliases mod_rewrite ---- htaccess AFNOG X Cairo, Egypt May 2009 Hervey Allen.
Introduction to MVC Controllers NTPCUG Tom Perkins, Ph.D.
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.
PHP “Personal Home Page Hypertext Pre-processor” (a recursive acronym) Allows you to create dynamic web pages and link web pages to a database.
Martin Kruliš by Martin Kruliš (v1.1)1.
Web Technologies Lecture 11 Implementing RESTful services.
CSC 2720 Building Web Applications Basic Frameworks for Building Dynamic Web Sites / Web Applications.
 An essential supporting structure of any thing  A Software Framework  Has layered structure ▪ What kind of functions and how they interrelate  Has.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 2: Introduction to IS2803 Rob Gleasure
Web programming Part 1: environment 由 NordriDesign 提供
How Web Database Architectures Work CPS181s April 8, 2003.
Introduction  “M” “V” “C” stands for “MODEL” “VIEW” “CONTROLLER”. ASP.NET MVC is an architecture to develop ASP.NET web applications in a different manner.
COSC 2328 – Web Programming.  PHP is a server scripting language  It’s widely-used and free  It’s an alternative to Microsoft’s ASP and Ruby  PHP.
Ruby on Rails. Web Framework for Ruby Designed to make it easier to develop, deploy, and maintain web applications Design with Model-View-Controller –almost.
CGS 3066: Web Programming and Design Spring 2016 PHP.
Basics Components of Web Design & Development Basics, Components, Design and Development.
L.A.M.P. İlker Korkmaz & Kaya Oğuz CS 350. Why cover a lecture on LAMP? ● Job Opportunities – There are many hosting companies offering LAMP as a web.
PHP using MySQL Database for Web Development (part II)
Class03 Introduction to Web Development (Hierarchy and the IDE)
CS 330 Class 7 Comments on Exam Programming plan for today:
Apache and... Virtual Hosts ---- aliases mod_rewrite ---- htaccess
MVC Architecture, Symfony Framework for PHP Web Apps
Play Framework: Introduction
Introduction to CodeIgniter (CI)
Unix System Administration
Web Software Model CS 4640 Programming Languages for Web Applications
ITM 352 Cookies.
Multitier Architecture, MySQL & PHP
MapServer In its most basic form, MapServer is a CGI program that sits inactive on your Web server. When a request is sent to MapServer, it uses.
How to get data from a form
MVC Framework, in general.
Web Browser server client 3-Tier Architecture Apache web server PHP
Lecture 1: Multi-tier Architecture Overview
The Model Layer What is Model?
Web Applications Best Practices
Developing a Model-View-Controller Component for Joomla
Lecture 5: Functions and Parameters
Web Programming Language
Tutorial 6 PHP & MySQL Li Xu
Back end Development CS Programming Languages for Web Applications
PHP Forms and Databases.
Client-Server Model: Requesting a Web Page
Web Programming Language
Back end Development CS Programming Languages for Web Applications
PHP By Prof. B.A.Khivsara Note: The material to prepare this presentation has been taken from internet and are generated only for students reference and.
Presentation transcript:

Introduction to MVC PHP Web Development Ivan Yonkov Training Manager Software University www.softuni.bg

PHP Web Development PHPMVC

Web App Structure PHP Web Development Typically Web Applications have structure that follows the architectural model(s) used in the application.

Web App Structure PHP Web Development Web Browser Presentation Presentation Logic Business Logic This is the usually scenario, not the necessary one. Anyway, in most of the cases an end user hits our page by opening the web browser and an HTML (presentation) is there. Optionally this HTML is controlled by conditional statements and loops – called presentation logic. In order the presentation logic to work, there’s a layer that checks whether the user can access this page, in which format they should receive the response, how the data should get through the layers and so forth. It’s called Business Logic. The Business Logic eventually contacts a Data Access Layer – this layer that knows how to access data. Usually it access data from a Database, so it contacts the last layer in the chain – the Database. Data Access Logic Database

PHP Controller Classes PHP Data Access Classes PHP Web Development PHP App Structure Web Browser Views: HTML + PHP PHP Controller Classes PHP Model Classes In typical PHP MVC Structure, the web browser sees our product – views, which are usually .php files that contains HTML and a little bit PHP to control the HTML Rendering. These .php files receives data through PHP Controller classes. These classes does invoke the Views and send them data as some kind of arguments. But in order the controller classes to receive data, they contact the model classes. They actually have the data and map it in a way the business scenario needed. Or maybe they don’t give be because of lack of privileges. The model layer is responsible for the business logic over the data. Models are populated by contacting the PHP Data Access classes that might contact the MySQL DB through the PDO for instance. PHP Data Access Classes MySQL

Data Processing PHP Web Development

Data Access Database Access Logic ORM Approach Direct Access PHP Web Development Data Access Database Access Logic ORM Approach Direct Access ORM Approach: $user = $userRepo->findById(4); $user->setName(“Johnathan”); $userRepo->save($user); Direct Access: $db->query(“UPDATE users SET name = “Johnathan” WHERE id = 4”); Map Tables to Classes Data Access Classes

Data Binding Data Binding Form Data View Data PHP Web Development Instead: public function edit() { $id = $_GET[‘id’]; $name = $_POST[‘name’]; // do smth } do: public function edit($id, UserBindingModel $user) { $name = $user->getName(); View data: public function index() { $this->view->name = “John”; $this->view->age = 24; $userViewModel = new UserViewModel(“John”, 24); return view($userViewModel); Map Form Data to Objects Map Variables to ViewModels

Front Controller PHP Web Development

Front Controller PHP Web Development Controller View HTTP Request What is "front controller"? Architectural design pattern for Web applications Front controller == centralized entry point for all requests Controller View 1010

Enough Theory!!! PHP Web Development

URL Rewrite <IfModule mod_rewrite.c> RewriteEngine On PHP Web Development URL Rewrite .htaccess <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_URI} !^/content/.*$ RewriteCond %{REQUEST_URI} !^/favicon\.ico$ RewriteRule ^ index.php </IfModule> In order this to work you first need to enable the mod_rewrite extension in your Apache webserver

URL Rewrite (2) $uri = $_SERVER['REQUEST_URI']; var_dump($uri); PHP Web Development URL Rewrite (2) $uri = $_SERVER['REQUEST_URI']; var_dump($uri);

PHP Web Development URL Rewrite (3)

Replace Nested Folders PHP Web Development URL Rewrite (4) $uri = $_SERVER['REQUEST_URI']; $self = explode("/", $_SERVER['PHP_SELF']); array_pop($self); $replace = implode("/", $self); $uri = str_replace($replace."/", "", $uri); Replace Nested Folders Our app may reside in nested folders structure e.g. /www/myapp/core/index.php It could be accessed through localhost:/myapp/core/ - we need to remove /myapp/core/ from the URI

PHP Web Development URL Rewrite (5) $params = explode("/", $uri); $controllerName = array_shift($params); $actionName = array_shift($params); var_dump($controllerName); var_dump($actionName); var_dump($params); Our app may reside in nested folders structure e.g. /www/myapp/core/index.php It could be accessed through localhost:/myapp/core/ - we need to remove /myapp/core/ from the URI

PHP Web Development URL Rewrite (6)

Dispatching PHP Web Development

PHP Web Development Dispatching Print “Hello World” when /hello/world is accessed. Print “Hello Software University” when /hello/softuni is accessed.

PHP Web Development Dispatching (2) if ($controllerName == "hello") { switch ($actionName): case "world": echo "Hello World"; break; case "softuni"; echo "Hello Software University"; break; endswitch; }

PHP Web Development Dispatching (3)

PHP Web Development Dispatching (4)

PHP Web Development

PHP Web Development

PHP Web Development