Web App. Framework
Download
Report
Transcript Web App. Framework
CSC 2720
Building Web Applications
Basic Frameworks for Building
Dynamic Web Sites / Web Applications
Web Application Framework
A web application framework is a software
framework that is designed to support the
development of dynamic websites and Web
applications.
Aims
Improve productivity
Promote code reuse
Minimize errors
Reduce cost of maintenance
Input-Process-Output
Input:
Extract form data, cookies, etc. from a HTTP request
Process
Validate data, authenticate user, check access right, etc.
Retrieve data from or update data in the storage layer
Apply business logic
Output
Format the output in HTML and CSS
Write PHP scripts to conditionally or iteratively generate
the output
Suggestion: Organizing the contents in a PHP script
<?php
// Validate input
// Process the input
// Store the output (including error status
// and messages if there is any) in some
// designated variables
?>
<!-Contains mainly HTML, CSS, and PHP scripts that
deal with presentation logic
-->
Suggestion: Organizing the contents in a PHP script
Commonly used codes should be made into
functions and placed in separate files (so they can
be reused). For examples, codes to
Authenticate a user
Establish a database connection
Retrieve data from a database
Validate the format of an email address or a credit card
number.
Codes that make up the business logic should also
be placed in separate files.
Modular Design
Presentation Layer
Commonly used
Functions
Business Logic
Data Access Layer
(PHP Functions to retrieve, store, or update data)
Data Storage Layer
(Database, Files, etc.)
Model-1 Architecture
http://website/app_folder/page1.php
page1.php
page2.php
pageN.php
…
Input Validation + Business Logic
Presentation Logic
Model-1 Architecture
Each PHP page is regarded as the focal point for
the entire application.
Each PHP page
Contains code for extracting HTTP request parameters
and call the business logic
Contains the presentation logics
Adv: Easy to add/remove pages
Suitable for small/simple application
Model-2 Architecture
http://website/app_folder/controller.php?action=p1
controller.php
controller.php can
pass the necessary
data to page1.php via
some global
variables.
page1.php
if ($action == 'p1') {
include("page1.php");
exit();
}
…
page2.php
pageN.php
…
Input Validation + Business Logic
Presentation Logic
Note: These files can be
placed in a folder that
cannot be accessed directly
via a URL.
Model-2 Architecture
One PHP script serves as a controller that
Handles requests, setup sessions
Performs authentication, validation
Decides what logic to invoke or which PHP script to
handle the business logic
Decides which PHP script to be used to present the
output
Adv: One entry point to the web application (easier
to enforce access control and perform user
authentication)
Suitable for large or complicated application