Enhancing a Simple PHP Application

Enhancing a Simple PHP Application

This project will take the existing e-commerce store we built earlier and enhance it with new techniques using the PHP programming language. By the end, you’ll be able to build an online t-shirt store with clean web addresses, basic search functionality, pagination, and more. You’ll also understand programming concepts like refactoring and separation of concerns.

Integrating Validation Errors

Our contact form currently checks that the information submitted by visitors to our site is valid, but we need to improve how validation errors get displayed. We’ll enhance the flow of our code that handles form submissions, displaying error messages within the context of the form and carefully avoiding a common security vulnerability by escaping our output.

Introducing the Project – 1:27
Setting an Error Message Variable – 5:55
Displaying the Error Message – 7:32
Re-Displaying the Submission – 4:13
Escaping Output – 4:32

Cleaning URLs with Subfolders

The web addresses in our store have various technical pieces in them, like a .php file extension. Cleaning up the web addresses can help optimize them for search engines, make them easier to remember or to guess, and make them more likely to endure the same over time. We’ll cover a number of concepts as we remove the extension, including subfolders, constants, and absolute and root-relative paths.

Introducing Subfolders – 5:42
Using Root-Relative Web Addresses – 4:16
Using Absolute Server Paths – 3:18
Introducing Constants – 9:21
Moving the Other Pages – 4:07

Cleaning URLs with Rewrite Rules

The web addresses in our store have various technical pieces in them, like question marks with variables after them. Cleaning up the web addresses can help optimize them for search engines, make them easier to remember or to guess, and make them more likely to endure the same over time. We’ll cover a number of concepts as we remove these pieces, including rewrite rules and htaccess files.

Introducing Rewrite Rules – 8:39
Get Variables and Rewrite Rules – 8:29
Redirecting Old Web Addresses – 3:35
Rewrite Rules with Query Strings – 3:43
Adding a Trailing Slash – 3:32

Refactoring the Codebase

Refactoring is the process of improving your code’s structure to make it easier to understand, maintain, and extend over time. We’ll re-organize the code we’ve written so far to follow some good practices around separating different types of code. We’ll discuss topics like automated duplication, models, and views. Finally, we’ll look at native PHP functions like array_reverse, as well as write a few new functions of our own.

Introducing Refactoring – 2:24
Duplicating SKU as an Array Element – 5:03
Modifying List View Code – 2:10
Separating Concerns: Models – 3:21
Moving Recent Products to the Model – 7:13
Separating Concerns: Views – 1:58
Separating Concerns: MVC – 3:58

Adding Search: Controller & View

As the number of shirts increases, visitors to our store may want to search the catalog for shirts that contain a specific keyword. This functionality will require a new page with a search form. We’ll create the page, writing the controller code to handle the form submission and the view code to display the form and the search results. We’ll also look at some more native PHP functions like empty.

Creating the Search Page – 5:11
Building the Search Form – 5:35
Handling the Form Submission – 8:08
Displaying the Products – 4:01
Accounting for Empty Results – 4:45

Adding Search: Model

As the number of shirts increases, visitors to our store may want to search the catalog for shirts that contain a specific keyword. This functionality will require a new function in the model to handle the search algorithm. We’ll examine the different data types for PHP variables and look at some more native PHP functions like strpos. We’ll also walk through how to use the online PHP documentation to learn about more native PHP functions.

Introducing the strpos Function – 4:18
Introducing Boolean Values – 6:13
Introducing the PHP Manual – 3:28
Introducing Identity Comparison – 6:22
Performing the Search – 5:13

Paginating a List: Controller

As the number of shirts increases, it can be helpful to present the shirts listing page across multiple pages with links between them. This functionality will require more robust controller code like using a GET variable to determine the page number and some of PHP’s native math functions to calculate which shirts should appear on each page.

Introducing Pagination – 3:45
Getting the Count of Products – 0:51
Retrieving the GET Variable – 3:28
Adjusting Larger Page Numbers – 5:18
Adjusting Invalid Page Numbers – 2:11
Calculating Shirts from Page Number – 4:23

Paginating a List: Model and View

As the number of shirts increases, it can be helpful to present the full list of shirts across multiple pages with links between them. This functionality will require a new function in our model code and new links in our view code. We’ll cover a new math operator, a new kind of loop, and a partial view for shared code.

Creating the Model Function – 3:06
Limiting the Products – 2:29
Testing Model Code – 4:41
Introducing While Loops – 3:52
Adding HTML Markup – 3:50
Using Partials – 2:40
Understanding Comments – 4:37

Facebook Comments