Top Banner
Date : 1/12/2012 Web Technology Solutions Class: Three-Tier Application Architecture and more PHP Programming Practice
80

Web Technology Solutions

Jan 21, 2016

Download

Documents

Tim

Web Technology Solutions. Class: Three-Tier Application Architecture and more PHP Programming Practice. Date : 1/12/2012. Tonight. Three Tier Architecture PHP and its oppositionPHP Syntax Review and Simple Debugging Techniques.Lab. Lab Preview. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Web Technology Solutions

Date : 1/12/2012

Web Technology SolutionsClass: Three-Tier Application Architecture and more PHP Programming Practice

Page 2: Web Technology Solutions

Tonight

✤ Three Tier Architecture PHP and its

oppositionPHP Syntax Review and Simple

Debugging Techniques.Lab

Page 3: Web Technology Solutions

Lab Preview

✤ PHP Basics: Working with variables, conditionals, managing arrays, clean commenting, and debugging.

✤ Homework: documentation and design.

Page 4: Web Technology Solutions

System Recap

✤ software system is a collection of interacting software components. Recall that the components of a system can also be considered as systems, called subsystems. Those subsystems (components) of a system that directly interact with each other do so through interfaces

Page 5: Web Technology Solutions

Modern web apps excel at all three - twitter, Facebook, digg, flickr, etc

Server Side SystemsAllow for High Availability(HA), Dynamic Data Interaction, Data Storage

Page 6: Web Technology Solutions

Web Applications Systems

Page 7: Web Technology Solutions

Which Systems To Use?

Page 8: Web Technology Solutions

Selecting Systems

✤ Being a technologist is understanding which system offers their client the maximum of benefits. How do you choose?

✤ Modern Web Applications collect various subsystems and make them their own system.

✤ Solves for HA, Interaction, Storage and Retrieval.

Page 9: Web Technology Solutions

Application Architecture

Page 10: Web Technology Solutions

System Models

✤ An Architecture Defines: What Important Systems are Needed and their Interfaces.

✤ A model is a simplified way to represent or think about a system of interest. Models are often represented using diagrams to show how components are related and organized.

✤ Two System Examples: Web App, Databases.

Page 11: Web Technology Solutions

Example System

Page 12: Web Technology Solutions

Common Models

✤ Database

Page 13: Web Technology Solutions

Common Models

✤ Web Servers

Page 14: Web Technology Solutions

Common Models

✤ Internet

Page 15: Web Technology Solutions

Common Models

✤ Load Balancer

Page 16: Web Technology Solutions

Web Systems

✤ Web Applications should scale gracefully. LAMP allows for that

✤ Note: the load balancer

✤ Multiple Redundant Web Servers

✤ Multiple DBs (master and slave)

✤ What is missing? CDN’s

Page 17: Web Technology Solutions

MySQL ExampleMySQL comes with many sub-systems

Page 18: Web Technology Solutions

How to Document a Model

✤ Models and Architecture add value as design documents.

✤ Include only the most important components of a system.

✤ Hide Details

Page 19: Web Technology Solutions

How to Document a Model

✤ Hide the details

✤ Reduce complexity and increases conceptualization making for easy buy-off.

✤ Avoid information overload

✤ Stakeholders and non-techies don’t care.

✤ Example: Three Tier system

Page 20: Web Technology Solutions

3-Tier Web System

✤ Typical Web solution where each tier provides specific types of service.

✤ 1. Presentation Layer: produces the user interface

✤ 2. Business Logic Layer: implements applications functionality

✤ 3. Data services Layer: provides data storage for the application

✤ Example: Detailed Model (note subsystems)

Page 21: Web Technology Solutions

Why PHP?

Page 22: Web Technology Solutions

PHP

✤ PHP: Ubiquitous. Easy to host and learn.

✤ PHP: tied in harmony to Linux, Apache, MySQL. Loads of devs and huge community.

✤ PHP is criticized because it is not strict in its promotion of best-of-breed coding practices. See php.net comments.

✤ PHP and PECL extend PHP

✤ PHP is liberating to rapidly develop ‘simple sites’ but scalable web apps?

Page 23: Web Technology Solutions

PHP vs. Other

✤ The debate with PHP vs. others. Understand each has their benefit.

✤ Ruby

✤ C#

✤ Java

✤ Python

Page 24: Web Technology Solutions

PHP vs. Ruby

✤ PHP vs. Ruby (Rails)

✤ Syntax akin to smalltalk. PHP is C based.

✤ PHP easier to host (rails ssh, root)

✤ PHP not strict. Ruby all OOP (everything object)

✤ PHP has many frameworks,

✤ Rails is MVC

Page 25: Web Technology Solutions

PHP vs. C#

✤ PHP vs. C# (.net)

✤ C# tied to the .NET framework

✤ C# bindings to allow for desktop apps

✤ Akin to Java in ability and behavior.

✤ has an MVC framework.

Page 26: Web Technology Solutions

PHP vs. Python

✤ PHP vs. Python (Django)

✤ Python has strict syntax control structure

✤ Python benchmarks

✤ PHP primarily web based - python extends beyond the web.

✤ Bad programmers are able to write bad programs in any language

Page 27: Web Technology Solutions

Best Practice

✤ Bad PHP: Three layers all in one (spaghetti code)

✤ Good PHP (MVC Design Pattern)

✤ Presentation: Templates (minimal PHP)

✤ Logic: All PHP to handle data transaction and state

✤ Business: PHP is used to abstract the Database. No real native SQL calls. PHP can be used for good or bad.

Page 28: Web Technology Solutions

Best Practice Tip

✤ Always develop a high level system architecture as part of the documentation deliverable.

✤ Clients love to know you’re taking care of the details.

Page 29: Web Technology Solutions

Best Practice Tip

✤ Prepare detailed low-level system and system diagrams for areas of risk or what I would be personally responsible for and will require prototyping.

✤ risk: something I haven’t coded before

Page 30: Web Technology Solutions

Best Practice Tip

✤ Focus on Rapid Application Development Techniques

✤ Be Agile

✤ Update quickly

✤ Verify assumptions

✤ Ask questions, find improvements

Page 31: Web Technology Solutions

Best Practice Tip

✤ Keep Documentation Current. Things change!

Page 32: Web Technology Solutions

Final Project Documentation

Start now.Lesson 3: Start documentingLesson 4: Much prototyping.Lesson 5: Documentation Complete.You’re building a professional application.

Page 33: Web Technology Solutions

Tools

Page 34: Web Technology Solutions

FTP

✤ Mac

✤ Transmit

✤ Cyberduck

✤ Coda

✤ PC

✤ SmartFTP

✤ FileZilla

✤ Firefox

Page 35: Web Technology Solutions

IDE

✤ Mac

✤ Coda

✤ Eclipse

✤ Textmate

✤ Dreamweaver

✤ PC

✤ PHP Designer

✤ Zend Developer

✤ notepad++ \ dreamweaver

Page 36: Web Technology Solutions

Firebuga preview

Page 37: Web Technology Solutions

Programming PHP

Page 38: Web Technology Solutions

PHP on Linux: First Steps

✤ Understanding how PHP is setup and configured on your installation of linux is critical to your success.

✤ phpinfo()

✤ php.ini

✤ Denied function, extensions, modules.

Page 39: Web Technology Solutions

PHP Basics

✤ All php code must start with <?

✤ All php code must end with ?>

✤ You might see <?php which is fine as well.

Page 40: Web Technology Solutions

PHP Basics

✤ Every PHP statement must end in a semicolon?

✤ echo “i love php”;

Page 41: Web Technology Solutions

PHP Basics

✤ if a webpage contains PHP, keep the extension as .php

✤ do not name it html.

Page 42: Web Technology Solutions

PHP Variables

✤ Variables store basic units of data that can control an application

✤ Variables in PHP start with a $ sign. Must start with char or _

✤ for example: $player

✤ setting variable: $player = “poodle”;

✤ variable reference: $player =& $music (points to same content in memory)

✤ restricted: $this (used in classes)

✤ destroy: unset();

Page 43: Web Technology Solutions

PHP Restricted Keywords

✤ Abstract, And, array(), As, Break, Case, catch, cfunction, Class, clone, Const, Continue, Declare, Default, die(), Do, echo(), Else, elseif, empty, enddeclare, endfor, endforeach, endif, endswitch, endwhile,final, for, foreach, function, global, if

Page 44: Web Technology Solutions

HTTP GET

✤ This method appends the form-data to the URL in name/value pairs

✤ This method is useful for form submissions where a user want to bookmark the result

✤ There is a limit to how much data you can place in a URL (varies between browsers), therefore, you cannot be sure that all of the form-data will be correctly transferred

✤ Never use the "get" method to pass sensitive information! (password or other sensitive information will be visible in the browser's address bar)

Page 45: Web Technology Solutions

HTTP POST

✤ This method sends the form-data as an HTTP post transaction

✤ Form submissions with the "post" method cannot be bookmarked

✤ The "post" method is more robust and secure than "get", and "post" does not have size limitations

Page 46: Web Technology Solutions

PHP Global Variables

✤ Pre-Defined SuperGlobal Vars - available in all scope.✤ usually indicated by underscore and caps✤ $GLOBALS✤ $_SERVER✤ $_GET✤ $_POST✤ $_COOKIE✤ $_SESSION✤ $_FILES✤ $_ENV✤ old style from php3 $HTTP_COOKIE_VARS

Page 47: Web Technology Solutions

PHP Variables

✤ Typically a variable has a lifespan of the current page (including pages that are inserted within the page you’re working).

✤ In OOP there are extended definitions of a variable that restrict usage.

✤ Golden Rule: Avoid the urge to scope globally.

Page 48: Web Technology Solutions

PHP Commenting

✤ Super basic:

// this is a single line comment

/* this is a comment */

/*

* this is a comment

*/

✤ best practice: good commenting

Page 49: Web Technology Solutions

PHP Commenting

/*

* Dev: Lincoln Mongillo

* Time Updated: 09.12.08 2:30pm

* File: email-validation.php

* Desc: validates a users email address

*/

Page 50: Web Technology Solutions

PHP Data Types

✤ Booleans

✤ Integers

✤ Floats

✤ Strings

✤ Arrays

✤ Objects

✤ Resource

Page 51: Web Technology Solutions

Boolean

✤ very basic type that allows you define what is True or False.

<? $playerActive = True; ?>

✤ True or False is often times what is returned to you when conditionally checking.

✤ PHP is often criticized because boolean expectations are not correct in rare-cases.

Page 52: Web Technology Solutions

Boolean

✤ False in PHP are:

✤ keyword “false”

✤ int 0

✤ floating point 0.0

✤ empty string

✤ array with zero elements

✤ obj with no vals

✤ NULL

Page 53: Web Technology Solutions

Integers

✤ a simple number. Note: an integer does not include a decimal.

<?php

$a = 3232; // decimal number

$a = -543; // a negative number

$a = 0133; // octal number (equivalent to 83 decimal)

is_int()

?>

Page 54: Web Technology Solutions

Floats

✤ a simple decimal representation of an integer. Note: different versions of PHP are more precise. hint: not precise - warning!

<?php

$a = 1.234; 

$b = 1.2e3; //exponential

is_float()

?>

Page 55: Web Technology Solutions

Strings

✤ a series of character data. PHP can support 256 characters. PHP 6 aims to support UTF-8 and unicode, allowing for more character types.

<?php

echo 'I own an apple iPod';

echo “I can also \n put in <b>html</b>”;

?>

Page 56: Web Technology Solutions

Arrays

✤ “An ordered map”, meaning a value is tied to a key.

<?php

$arr = array("name" => "bob", 12 => true);echo $arr["name"]; // bob

?>

✤ keys: associative, numerical or both!

✤ values: can be any type, including additional arrays

Page 57: Web Technology Solutions

Constants

✤ Allows you to define a non-changing data value.

<?php

define("URL", "http:www.site.com");

define("PASSWORD", "bosco");

?>

✤ By convention: usually uppercase.

Page 58: Web Technology Solutions

Expression

✤ Expressions are the basic building blocks of PHP (or most any programming language)

$var = 5; // setting

$var == 5; // equal to (=== to strict)

$var != 5 // not equal;

$var++; // increment; (or --)

Page 59: Web Technology Solutions

Expression

✤ Expressions are the basic building blocks of PHP (or most any programming language)

< //less than

> //greater than

<= //less then or equal to

>= //greater than or equal to

Page 60: Web Technology Solutions

Operators

✤ Operators allow you to extend on an expression. There are three types

✤ unary: operates on one expression

✤ binary: operates against two expressions

✤ ternary: operates on two, depending on a third option (like an if-statement)

Page 61: Web Technology Solutions

Unary Operators

✤ unary: operates on one expression

✤ The most common example is the !, which means “is not”

if(!($dog)){

echo “than cat”:

}

Page 62: Web Technology Solutions

Binary Operators

✤ binary: operates on two expression

✤ The most common example is the || or &&.

✤ || (double pipe) is “or”

✤ && (double amps) is “and”

if(($dog == “chuck”) && ($cat == “jim”)){

echo “than the dogs name is chuck and the cats jim”;

}

Page 63: Web Technology Solutions

Ternary Operators

✤ ternary: operates on two, depending on a third option (like an if-statement)

✤ The basics work like an if statement (?:)

✤ The expression (expr1) ? (expr2) : (expr3) evaluates to expr2 if expr1 evaluates to TRUE, and expr3 if expr1 evaluates to FALSE.

// Example usage for: Ternary Operator

$action = (empty($_POST['action'])) ? 'default' : $_POST['action'];

Page 64: Web Technology Solutions

Control Operators

✤ ifelseelseifwhiledo\whilefor

✤ Take control of your logic with basic control structures. PHP uses many classics from more established languages, like C

✤ foreachbreakcontinue

✤ return

✤ require

✤ include

Page 65: Web Technology Solutions

if statement

$dog = true;

if($dog){

$myPet = “is a dog”;

}

//eval to true

Page 66: Web Technology Solutions

if-else statement

$dog = true;

if($dog){

$myPet = “is a dog”;

}else{

$myPet = “is not a dog”;

}

//eval to true

Page 67: Web Technology Solutions

if-else statement

$dog = true;

if($dog){

$myPet = “is a dog”;

}elseif($dog = “dead”){

$myPet = “is not a living dog”;

}else{

}

Page 68: Web Technology Solutions

switch statement

switch ($i) {

    case 0:

        echo "i equals 0";

    case 1:

        echo "i equals 1";

    case 2:

        echo "i equals 2";

break;

default:

echo “no number”;

}

Page 69: Web Technology Solutions

While Loop

$i = 1;

while ($i <= 100) {

echo “currently “ . $i . “<br/>”;

    echo “add a few “ . $i++; 

}

//while something is true, do something

Page 70: Web Technology Solutions

Do While Loop

<?php

//Do something. Check if true. Continue

$i = 0;

do {

    echo $i++;

} while ($i > 0);

?>

Page 71: Web Technology Solutions

5min Developer ChallengeCreate a while loop that counts up to a hundred on the screen with line breaks

Page 72: Web Technology Solutions

For Loop

<?php

for ($i = 1; $i <= 10; $i++) {

    echo $i;

}

?>

Page 73: Web Technology Solutions

For Each Loop

<?php

$arr = array(1, 2, 3, 4);

foreach ($arr as &$value) {

    $value = $value * 2;

}

?>

Page 74: Web Technology Solutions

5min Developer ChallengeCreate a foreach loop that prints the contents of an array of presidents.

Page 75: Web Technology Solutions

Functions

✤ functions are incapsulated and allows for code to be portable and reusable (if developed correctly)

function sayMyName($first, $last)

{

    echo "Example function.\n";

var retval = “my name is “. $first . “ “ .$last;

    return $retval;

}

Page 76: Web Technology Solutions

PHP Functions List

✤ See PHP website for a massive amount of predefined functions available to you via the PHP API (application programming interface).

Page 77: Web Technology Solutions

Final Project

✤ Your final project is an online survey. This application will allow admin to create various surveys, collect user response, and analyze data.

✤ I am your client. I want a survey tool that I can gather information from people. I want it to be easy and secure. Ask me questions.

Page 78: Web Technology Solutions

Final Project

✤ Data Model will be shown next week

✤ Surveys

✤ Questions and Answers

✤ Responses and Response Answers

✤ Users (including admin)

✤ Possible methods

✤ create new question, delete question, modify question

✤ show survey results, etc

Page 79: Web Technology Solutions

Lab & Next Week

✤ Documentation:

✤ Develop Application Architecture (visio is great for this)

✤ PHP:

✤ Create a simple survey and PHP script that allows for flow control using conditionals.

✤ Create a simple form and PHP script that validates user input.

See you Thursday!

Page 80: Web Technology Solutions

Lab & Next Week

✤ “PHP Abstraction, Server Side Includes, Self Pointing PHP Scripts, and Function Development.”

✤ Reading for Next Week

✤ Chapter 3

See you Thursday!