Ron Fredericks writes: I am LectureMaker’s video platform technologist. So I thought I would demonstrate some of my sample code in building a simple website demo.
The demo consists of three pages that feature the following code
- PHP programming with OO and model-view-controller (MVC) architecture
- SQL file to create a new table and load some sample user data
- PHP sessions and OO MySQL Data Manager
- Use of CSS style sheet and tags for web page layout and forms management
- A RESTful API allowing users to move data between the three pages
Visit the running project’s website here:
Download a copy of the project’s source code from GitHub:
What is OOP?
Object Oriented Programming, or OOP, invokes the use of classes to organize the data and structure of an application:
- Objects: instances of a class
- Inheritance: ability to pass characteristics and behaviors from a base class
- Access Modifiers: ability to protect data and methods
- Interfaces: a form of abstract class that acts as a model for creating a derived class
- PHP 5 Built-in Classes: Standard PHP Library (SPL), mysqli, PDO, SQLite, XML support, relfection, Iterator interface, magic methods, objects passed by reference
- Design Patterns: a reusable set of solutions that solve practical problems
What is MVC?
Model–View–Controller (MVC) is an architectural pattern used in software engineering:
- Model handles database logic. Code in the model connects to the database and provides an abstraction layer.
- Controller represents the business (application) logic i.e. all our ifs and else.
- View provides the presentation logic i.e our HTML/XML/JSON code.
What is REST?
Representational state transfer (REST) is a predominant web API design model for distributed systems. PHP examples include:
- Use FORM tag with GET or POST to send data to another web page.
- Use cURL to set the URL, create array of POST data, set options such as return XML data, and make request.
- Create a POST request by opening a TCP connection to the host using fsockopen(), then use fwrite() on the handler returned from fsockopen().