Model View Controller.

Slides:



Advertisements
Similar presentations
The Librarian Web Page Carol Wolf CS396X. Create new controller  To create a new controller that can manage more than just books, type ruby script/generate.
Advertisements

Introduction to MVC Adding a View Page NTPCUG Tom Perkins, Ph.D.
Model View Controller Bayu Priyambadha, S.Kom. PHP & MVC  The model view controller patternis the most used pattern fortoday’s world web applications.
SERVER web page repository WEB PAGE instructions stores information and instructions BROWSER retrieves web page and follows instructions Server Web Server.
Multiple Tiers in Action
Struts. Agenda Preface Struts and its components An example The architecture required for Struts Applications.
UNIT-V The MVC architecture and Struts Framework.
FUNCTIONS AND STORED PROCEDURES & FUNCTIONS AND PROTECTING A DB AND PHP (Chapters 9, 15, 18)
Lecture 19 Web Application Frameworks Boriana Koleva Room: C54
Standalone Java Application vs. Java Web Application
1 Dr Alexiei Dingli Web Science Stream Introducing Rails.
Zend Framework Quick start Faheem Abbas Software engineer.
Pemrograman Web MVC Programming and Design Pattern in PHP 5.
_______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications1.
Intro to PHP Carl-Erik Svensson. What is PHP? PHP is a widely-used general-purpose scripting language that is especially suited for Web development and.
Model View Controller MVC Web Software Architecture.
Martin Kruliš by Martin Kruliš (v1.1)1.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Zend Framework. What is the Zend Framework? Zend Framework is a high quality and open source framework for developing Web Applications and Web Services.
APACHE STRUTS ASHISH SINGH TOMAR ast2124. OUTLINE Introduction The Model-View-Controller Design Pattern Struts’ implementation of the MVC Pattern Additional.
Thomas Burleson. Using MVC with Flex & Coldfusion Projects June 27, 2007 See how Coldfusion MVC is similar to Flex MVC…
Presentation Title Subheading goes here.
Dive into web development
Intro to HTML CS 1150 Spring 2017.
Form Data (part 2) MIS 3502, Fall 2015 Jeremy Shafer Department of MIS
Intro to HTML CS 1150 Fall 2016.
MVC Architecture, Symfony Framework for PHP Web Apps
PHP with HTML.
Uppingham Community College
Play Framework: Introduction
PHP Arrays Functions.
Web Technologies PHP 5 Basic Language.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Introduction to CodeIgniter (CI)
MVC and other n-tier Architectures
Content Management System
Introduction to MVC PHP Web Development Ivan Yonkov Training Manager
Unit 6-Chapter 2 Struts.
PHP FORM HANDLING Post Method
How to get data from a form
Presentation Title Subheading goes here.
Intro to PHP & Variables
PHP: Output Formatting
A guide to HTML.
Title 1  Our experience drives us forward 2.
Model View Controller Bayu Priyambadha, S.Kom.
The following content applies to this page only
Authors and Institutions Can Go Here
Unfortunately I did not record the beginning of this lecture.
Author, Company and/or Logo Information
Web Applications Best Practices
Author, Company and/or Logo Information
PHP: Database Basic Selection FdSc Module 109
Software Engineering for Internet Applications
Insert Your Poster Title Here
Author, Company and/or Logo Information
Model View Controller.
Authors and Affiliations
BOF #2 – Introduction to PHP and MySQL
PHP an introduction.
Type your presentation title here
Unit 10 The Web Book Test.
Client-Server Model: Requesting a Web Page
Model View Controller Bayu Priyambadha, S.Kom.
Main Title Here Topic 2 Topic 3 Topic 4 Topic 5
Authors and Affiliations
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.
Struts BY: Tejashri Udavant..
Authors and Affiliations
Presentation transcript:

Model View Controller

PHP & MVC The model view controller pattern is the most used pattern for today’s world web applications It has been used for the first time in Smalltalk and then adopted and popularized by Java At present there are more than a dozen PHP web frameworks based on MVC pattern

PHP & MVC The model is responsible to manage the data The view (presentation) is responsible to display the data provided by the model in a specific format The controller handles the model and view layers to work together

PHP & MVC

PHP & MVC

model/Book.php <?php class Book { public $title; public $author; public $description; public function __construct($title, $author, $description) { $this->title = $title; $this->author = $author; $this->description = $description; } ?>

model/Model.php <?php include_once("model/Book.php"); class Model { public function getBookList() { // here goes some hardcoded values to simulate the database return array( "Jungle Book" => new Book("Jungle Book", "R. Kipling", "A classic book."), "Moonwalker" => new Book("Moonwalker", "J. Walker", ""), "PHP for Dummies" => new Book("PHP for Dummies", "Some Smart Guy", "") ); } public function getBook($title) // we use the previous function to get all the books // and then we return the requested one. // in a real life scenario this will be done through // a database select command $allBooks = $this->getBookList(); return $allBooks[$title]; ?>

view/viewbook.php <html> <head></head> <body> echo 'Title:' . $book->title . '<br/>'; echo 'Author:' . $book->author . '<br/>'; echo 'Description:' . $book->description . '<br/>'; ?> </body> </html>

view/booklist.php <html> <head></head> <body> <table> <tbody> <tr><td>Title</td><td>Author</td><td>Description</td></tr> </tbody> <?php foreach ($books as $book) { echo '<tr><td><a href="index.php?book=' . $book->title . '">' . $book->title . '</a></td><td>' . $book->author . '</td><td>' . $book->description . '</td></tr>'; } ?> </table> </body> </html>

controller/Controller.php <?php include_once("model/Model.php"); class Controller { public $model; public function __construct() { $this->model = new Model(); }

controller/Controller.php public function invoke() { if (!isset($_GET['book'])) // no special book is requested, we'll show a list of all available books $books = $this->model->getBookList(); include 'view/booklist.php'; } else // show the requested book $book = $this->model->getBook($_GET['book']); include 'view/viewbook.php'; ?>

index.php <?php // All interaction goes through the index and is forwarded // directly to the controller include_once("controller/Controller.php"); $controller = new Controller(); $controller->invoke(); ?>

PHP & MVC

Thank you...