Presentation is loading. Please wait.

Presentation is loading. Please wait.

Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.

Similar presentations


Presentation on theme: "Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy."— Presentation transcript:

1 Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy

2 Agenda Rest of the year Rest of the year OOP OOP Page Templates Page Templates Lab Lab

3 Rest of the year Dec 5 – Object Oriented Programming Dec 5 – Object Oriented Programming Dec 12 – OPTIONAL – Final Project Lab Dec 12 – OPTIONAL – Final Project Lab Dec 14 – Final Projects Due Dec 14 – Final Projects Due

4 IMPORTANT NOTE The life cycle in PHP is the length of time it takes the server to find the file, process the information, and send the completed static HTML back to the client.

5 Object Oriented Programming (OOP) Class: A Class is template for an object, a user- defined datatype that contains the variables, properties and methods in it. Class: A Class is template for an object, a user- defined datatype that contains the variables, properties and methods in it. Instance: One can have an instance of a class; the instance is the actual object created at run-time. Instance: One can have an instance of a class; the instance is the actual object created at run-time. Method: Method is a set of procedural statements for achieving the desired result. Method: Method is a set of procedural statements for achieving the desired result. Types of class and functions and variables are public, protected or private. Types of class and functions and variables are public, protected or private. http://www.devarticles.com/c/a/PHP/Object-Oriented-Programming-in-PHP/

6 Object Oriented Programming (OOP) private - Only the current class will have access to the field or method. private - Only the current class will have access to the field or method. protected - Only the current class and subclasses (and sometimes also same-package classes) of this class will have access to the field or method. protected - Only the current class and subclasses (and sometimes also same-package classes) of this class will have access to the field or method. public - Any class can refer to the field or call the method. public - Any class can refer to the field or call the method. static - resolved statically based on the class they are called on; and not dynamically. Static methods cannot be overridden. static - resolved statically based on the class they are called on; and not dynamically. Static methods cannot be overridden. http://php.net/manual/en/language.oop5.basic.php

7 OOP Mapping Car FordChevy Honda Class Methods driveCar() setEngine() getEngine() Variables private engine public price Instances of class Car

8 Class v Instances CLASS ========= Wheels Color Name INSTANCE #1 ========= Wheels = 2 Color = Red Name = Honda INSTANCE #4 ========= Wheels = 4 Color = Blue Name= Ford INSTANCE #3 ========= Wheels = 4 Color = Red Name = Chevy INSTANCE #2 ========= Wheels = 10 Color = Black Name = Kensworth All Instances exist for as long a page is in memory on the server

9 IMPORTANT NOTE Many times a PHP class is stored in its own file. (e.g. shape.class.php) This file is then included using the include_once(“shape.class.php”) functionality.

10 PHP OOP Syntax <?php // create a class class shape { some code… some code…} // creates an instance of the object $myshape = new shape(); ?> http://www.phpro.org/tutorials/Object-Oriented-Programming-with-PHP.html

11 PHP OOP Syntax // define variables and type public $wheels; public $color; private $model; const MSG = "Hello World"; http://www.phpro.org/tutorials/Object-Oriented-Programming-with-PHP.html

12 PHP OOP Syntax // define methods public function getmodel () { return $this->model; } public function setmodel($modelname) { $this->model = $modelname; } http://www.phpro.org/tutorials/Object-Oriented-Programming-with-PHP.html

13 PHP OOP Syntax // new instance $myshape = new shape(); // accessing information within the instance $myshape->side = 4; $area = $myshape->getArea(); http://www.phpro.org/tutorials/Object-Oriented-Programming-with-PHP.html

14 IMPORTANT NOTE When in a class instance, all the variables have the same name from instance to instance, you reference to variable is through the following syntax: $this->variableName

15 PHP OOP Terminology Inheritance is a process in which a class inherits all the state and behavior of another class. Inheritance is a process in which a class inherits all the state and behavior of another class. Abstraction refers to the act of representing essential features without including the background details or explanations. Abstraction refers to the act of representing essential features without including the background details or explanations. Encapsulation conceals the functional details of a class from objects that send messages to it. Encapsulation conceals the functional details of a class from objects that send messages to it. Polymorphism allows the programmer to treat derived class members just like their parent class's members. Polymorphism allows the programmer to treat derived class members just like their parent class's members. http://en.wikipedia.org/wiki/Object-oriented_programming

16 PHP OOP Terminology getter / setter methods : pair of methods to allow access to private variables (e.g. getVariable & setVariable) getter / setter methods : pair of methods to allow access to private variables (e.g. getVariable & setVariable) constructor / destructor methods : pair of methods that run automatically on new class instance of instance destruction. (e.g, __construct & __destruct) constructor / destructor methods : pair of methods that run automatically on new class instance of instance destruction. (e.g, __construct & __destruct) http://en.wikipedia.org/wiki/Object-oriented_programming

17 Tutorials on PHP OOP http://www.youtube.com/watch?v=wpGJz4o2a bs&feature=related http://www.youtube.com/watch?v=wpGJz4o2a bs&feature=related http://www.youtube.com/watch?v=wpGJz4o2a bs&feature=related http://www.youtube.com/watch?v=wpGJz4o2a bs&feature=related http://www.tutorialized.com/tutorials/PHP/OO P/1 http://www.tutorialized.com/tutorials/PHP/OO P/1 http://www.tutorialized.com/tutorials/PHP/OO P/1 http://www.tutorialized.com/tutorials/PHP/OO P/1

18 Questions?

19 Final Project Create a PHP website using pieces of code and modules we learned in class Create a PHP website using pieces of code and modules we learned in class Make the site look like a finished product that you can share as a indication of your skills Make the site look like a finished product that you can share as a indication of your skills You will be graded on looks, details and demonstration of php knowledge You will be graded on looks, details and demonstration of php knowledge Send email to rob.loy@gmail.com with URL to input form file before 6pm on Dec 14. Send email to rob.loy@gmail.com with URL to input form file before 6pm on Dec 14.rob.loy@gmail.com


Download ppt "Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy."

Similar presentations


Ads by Google