Skip to content
Kalam edited this page Mar 1, 2024 · 1 revision

index.php Documentation

Overview

  • The index.php file serves as the entry point for the website.
  • It handles routing incoming HTTP requests to the appropriate controller functions and views.
  • This document provides an overview of the file's structure and functionality.

Table of Contents

Routing

  • The index.php file employs a simple routing mechanism to direct incoming requests to specific controller functions.
  • It utilizes the $_SERVER['REQUEST_URI'] variable to determine the requested URL path and then switches on it to invoke the appropriate handler function.

/ (root route)

Displays the home page

/aboutus

Displays the about us page

/login

Handles user login requests

  • GET will display the login page
  • POST will attempt to log the user in
    • Requires usernameOrEmail and password to be supplied

/register

Handles user registration requests

  • GET will display the registration page
  • POST will attempt to register the user

/logout

Logs out the user

/contactpage

Displays the contact page

/basket

Displays the basket page

/product?productID=x

Displays individual product page

  • Requires productID=x to be added where x is the ID of a product

/products?category=x

Displays products page and optionally filters by category

  • Optional category=x to be added where x is the category of products to be displayed

/add-to-basket

Adds a product to the basket

  • POST will add a product to the basket
    • Requires productID and quantity to be supplied

/update-basket

Updates the a product in the basket

  • POST will update a product in the basket
    • Requires productID and quantity to be supplied

/checkout

Displays the checkout page

/checkoutProcess

Handles the checkout process

/orderSuccess

Displays the order success page

/orderFailed

Displays the order failed page

/customer

Displays the customer page

/change-password

Handles the change password process

  • POST will change the user's password
    • Requires current_password, new_password and confirm_password to be supplied

Default route

Displays a 404 error page

Functions

  • The index.php file contains a number of functions that are used to handle the routing and rendering of views.

handleHomeRquest()

Handles home page requests

Return void

handleAboutUsRequest()

Handles about us page requests

Return void

handleAboutUsRequest()

Handles about us page requests

Return void

handleLoginRequest()

Handles login page requests

Return void

handleRegisterRequest()

Handles register page requests

Return void

handleLogoutRequest()

Handles logout requests

Return void

handleContactPageRequest()

Handles contact page requests

Return void

handle404Request()

Handles 404 requests

Return void

handleProductPageRequest()

Handles product page requests

Return void

handleProductsPageRequest()

Handles products page requests

Return void

handleAddToBasketRequest()

Handles add to basket requests

Return void

handleUpdateBasketRequest()

Handles update basket requests

Return void

handleBasketPageRequest()

Handles basket page requests

Return void

handleCheckoutPageRequest()

Handles checkout page requests

Return void

handleCheckoutProcessRequest()

Handles checkout process requests

Return void

handleCustomerPageRequest()

Handles customer page requests

Return void

handleChangePasswordRequest()

Handles change password requests

Return void