Presentation is loading. Please wait.

Presentation is loading. Please wait.

Date : 02/03/2014 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

Similar presentations


Presentation on theme: "Date : 02/03/2014 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD."— Presentation transcript:

1 Date : 02/03/2014 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD

2 Tonight ✤ CRUD Redux ✤ Hands On Functions\Arrays ✤ Objects in PHP ✤ OOP Design Patterns ✤ Lab

3 Lab Preview ✤ Continue to build a simple CRUD app with the presidents table.

4 CRUD Review Create, Read, Update and Delete. How To, Tips, Tricks

5 Array and Function Challenges 4 quick challenges to test your programming skills.

6 Array Challenge #1 $arr = array("name", "age", "race", "job");Search through this array and find the item “race” and return the key of that item.

7 Array Challenge #2 Find only what is different in these two arrays and return those unique elements. $array1 = array(1 => "WA", "CA", "UT", "MT");$array2 = array(2 => "CA", "MT", "UT");

8 Function Challenge #1 Create a custom function that takes two array’s and combines those arrays into one array and return a single array. $array1 = array(1 => "WA", "CA", "UT", "MT");$array2 = array(2 => "VA", "NV", "OR");

9 Function Challenge #2 With the following string, break up each word and put the contents of each word into an array. Then echo out the contents of that array. $string = “Tomato Sausage Cheese Peppers Mushrooms”;

10 OOP in PHP ✤ Object Oriented Programming ✤ Objects and Classes ✤ PHP4 vs PHP5 ✤ Design Patterns ✤ Example

11 OOP in PHP ✤ Objects are discrete bundles of functions relating a concept (database connections, image creation, managing users) ✤ Objects work together to create applications. ✤ Service multiple projects with a single set of code. ✤ Code is portable, encapsulated, reusable and easier to debug.

12 OOP Example

13 OOP Car ✤ Functions of a car ✤ Accelerate, Stop, Steering ✤ How? (implementation) ✤ Gas Pedal, Engine ✤ Breaks ✤ Steering and Wheels ✤ Care how it works? No.

14 Object Oriented Programming ✤ What is an object: ✤ A “copy” or “instance” of a class. ✤ Objects have properties (color, speed, horsepower, seats) ✤ Objects have methods (accelerate, stop, steering).

15 Object Oriented Programming ✤ <?php ✤ /* ✤ * File Name: car ✤ * Date: November 18, 2010 ✤ * Author: Lincoln Mongillo ✤ * Description: Manages Car ✤ */ ✤ class Car ✤ { ✤ } ✤ ?>

16 Object Oriented Programming ✤ <?php ✤ $myRaceCar = new Car(); ✤ $myRaceCar -> accelerate(55); ✤ ?>

17 Object Oriented Programming ✤ Car = a basic blueprint that represents any car. ✤ color ✤ wheels ✤ seats ✤ horsepower ✤ With Car we can “create” other types of speciality cars: dump trucks, sports cars. How? Classes can “inherit” properties and methods from other classes.

18 Object Oriented Programming Car race car truck wheels: 4 color: white seats: 4 horsepower: 8 wheels: 4 color: white seats: 2 horsepower: 200 wheels: 4 color: white seats: 4 horsepower: 200 wheels: 4 color: white seats: 4 horsepower: 200 wheels: 4 color: red seats: 8 horsepower: 100

19 Object Oriented Inheritance ✤ <?php ✤ /* ✤ * File Name: RaceCar ✤ * Date: November 18, 2008 ✤ * Author: Lincoln Mongillo ✤ * Description: Manages RaceCars ✤ */ ✤ class RaceCar extends Car ✤ { ✤ } ✤ ?>

20 Object Oriented Polymorphism A Truck vs. Race Car come from car. Extending a class allows for “Polymorphism” which allows you to perform different tasks based on the context you’re using it in. Example: stop() between truck vs. racecar is somewhat the same but different because of the nature of the truck (size) and racecar (speed). It might implement the method differently to get the result.

21 Object Oriented Encapsulation ✤ Don’t need to know how it works (members functions or props) ✤ You just need to know what you can do (available methods - interface)

22 Object Oriented Encapsulation ✤ How do you know what you can use? ✤ Levels of visibility ✤ public: means that a class member is visible and usable / modifiable by everyone - default in PHP ✤ private: means that a class member is only usable / modifiable by the class itself ✤ protected: means that a class member is only usable / modifiable by the class itself and eventual sub-classes

23 Class Constructor - PHP4 ✤ <?php ✤ class Car ✤ { ✤ public function Car() { ✤ echo "We just created and object!"; ✤ } ✤ ?>

24 Class Constructor - PHP5 ✤ <?php ✤ class Car ✤ { ✤ function __construct() { ✤ echo "We just created and object!"; ✤ } ✤ ?>

25 Class Constructor - Properties ✤ <?php ✤ class Car ✤ { ✤ private $color; ✤ private $wheels; ✤ private $seats; ✤ function __construct() { ✤ $this->color = “OxFFFFF”; ✤ $this->wheels = 4; ✤ } ✤ ?>

26 Class Constructor - Properties ✤ function __construct() { ✤ $this->color = “OxFFFFF”; ✤ $this->wheels = 4; ✤ ✤ // $this is a reference to the object that is calling it. ✤ $truck = new Car(); // $this = truck.

27 Object Oriented Programming Image Example Database Example

28 Lab & Next Week ✤ Please send me your Survey in word doc format. ✤ Your personal DB will be updated next week and we will start working on the app.

29 Lab & Next Week ✤ Homework ✤ Complete Presidents CRUD system

30 Lab & Next Week ✤ Next week we will ✤ Create Registration system ✤ Create Login w\ Encrypt Password. ✤ Security and Authorization ✤ Reading: Chapter 8 See you Tuesday!


Download ppt "Date : 02/03/2014 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD."

Similar presentations


Ads by Google