PHP Classes

How to Learn to Implement PHP Applications Using a PHP MVC Framework: Example application using an MVC framework

Recommend this page to a friend!
  Info   View files Example   View files View files (42)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Last Updated Ratings Unique User Downloads Download Rankings
2024-04-20 (27 days ago) RSS 2.0 feedNot enough user ratingsTotal: 95 This week: 27All time: 9,855 This week: 3Up
Version License PHP version Categories
php_framework 1.0.0Custom (specified...8Libraries, Design Patterns, PHP 8, Ap...
Description 

Author

This package provides an example application using an MVC framework.

It provides a PHP applications built using controller, service and middleware classes that use framework classes that help using the MVC design pattern.

Currently, the framework provides the following classes:

- A base controller

- Request handler

- Request dispatcher

- Error handler

- Middleware request handler

- Migration

- Model

- Request

- Request

- Router

Picture of Faris AL-Otabi
  Performance   Level  
Name: Faris AL-Otabi <contact>
Classes: 14 packages by
Country: Saudi Arabia Saudi Arabia
Innovation award
Innovation award
Nominee: 3x

Example

<?php

declare(strict_types=1);

define("ROOT_PATH", dirname(__DIR__));

require
ROOT_PATH . "/vendor/autoload.php";

$dotenv = Dotenv\Dotenv::createImmutable(ROOT_PATH);

$dotenv->load();

set_error_handler("Framework\ErrorHandler::handleError");

set_exception_handler("Framework\ErrorHandler::handleException");

$router = require ROOT_PATH . "/config/routes.php";

$container = require ROOT_PATH . "/config/services.php";

$middleware = require ROOT_PATH . "/config/middleware.php";

$dispatcher = new Framework\Dispatcher($router, $container, $middleware);

$request = Framework\Request::createFromGlobals();

$response = $dispatcher->handle($request);

$response->send();


Details

Welcome to the PHP MVC Framework

This is a simple MVC framework for building web applications in PHP. It's free and open-source.

It was created for the Write PHP Like a Pro: Build an MVC Framework from Scratch course.

That course explains how the framework is put together, building it step-by-step, from scratch. If you've taken the course, then you'll already know how to use it.

If not, please look at the example code in the config and src/App folders for examples of how to use it.

DISCLAIMER

This framework was developed as a teaching example on the aforementioned course. The idea is that by developing this framework on that course, you'll understand how frameworks like Laravel work. No warranty is provided. For more details please see the licence.

Starting an Application using this Framework

  1. First, download the framework, either directly or by cloning the repo.
  2. Configure your web server to have the public folder as the web root.
  3. Make a copy of the .env.example file and call it .env, and enter your database configuration data.
  4. Create routes, controllers, views, models, middleware etc.

Build This Framework From Scratch

Signup for the course here and understand how this framework is built from scratch, putting it all together step by step.


  Files folder image Files  
File Role Description
Files folder imageconfig (4 files)
Files folder imagepublic (3 files)
Files folder imagesrc (2 directories)
Files folder imageviews (3 files, 2 directories)
Accessible without login Plain text file .htaccess Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  config  
File Role Description
  Accessible without login Plain text file app.php Aux. Auxiliary script
  Plain text file middleware.php Class Class source
  Accessible without login Plain text file routes.php Example Example script
  Plain text file services.php Class Class source

  Files folder image Files  /  public  
File Role Description
  Accessible without login Plain text file .htaccess Data Auxiliary data
  Accessible without login Plain text file example.css Data Auxiliary data
  Accessible without login Plain text file index.php Example Example script

  Files folder image Files  /  src  
File Role Description
Files folder imageApp (1 file, 3 directories)
Files folder imageFramework (12 files, 1 directory)

  Files folder image Files  /  src  /  App  
File Role Description
Files folder imageControllers (1 file, 1 directory)
Files folder imageMiddleware (3 files)
Files folder imageServices (1 file)
  Plain text file Database.php Class Class source

  Files folder image Files  /  src  /  App  /  Controllers  
File Role Description
Files folder imageAdmin (1 file)
  Plain text file Home.php Class Class source

  Files folder image Files  /  src  /  App  /  Controllers  /  Admin  
File Role Description
  Plain text file Users.php Class Class source

  Files folder image Files  /  src  /  App  /  Middleware  
File Role Description
  Plain text file AuthNeeded.php Class Class source
  Plain text file ChangeRequestExample.php Class Class source
  Plain text file ChangeResponseExample.php Class Class source

  Files folder image Files  /  src  /  App  /  Services  
File Role Description
  Plain text file Settings.php Class Class source

  Files folder image Files  /  src  /  Framework  
File Role Description
Files folder imageExceptions (1 file)
  Plain text file Controller.php Class Class source
  Plain text file ControllerRequestHandler.php Class Class source
  Plain text file Dispatcher.php Class Class source
  Plain text file ErrorHandler.php Class Class source
  Plain text file MiddlewareInterface.php Class Class source
  Plain text file MiddlewareRequestHandler.php Class Class source
  Plain text file Migration.php Class Class source
  Plain text file Model.php Class Class source
  Plain text file Request.php Class Class source
  Plain text file RequestHandlerInterface.php Class Class source
  Plain text file Response.php Class Class source
  Plain text file Router.php Class Class source

  Files folder image Files  /  src  /  Framework  /  Exceptions  
File Role Description
  Plain text file PageNotFoundException.php Class Class source

  Files folder image Files  /  views  
File Role Description
Files folder imageHome (1 file)
Files folder imageProducts (6 files)
  Accessible without login Plain text file 404.php Aux. Auxiliary script
  Accessible without login Plain text file 500.php Aux. Auxiliary script
  Accessible without login Plain text file base.mvc.php Aux. Auxiliary script

  Files folder image Files  /  views  /  Home  
File Role Description
  Accessible without login Plain text file index.mvc.php Aux. Auxiliary script

  Files folder image Files  /  views  /  Products  
File Role Description
  Accessible without login Plain text file delete.mvc.php Aux. Auxiliary script
  Accessible without login Plain text file edit.mvc.php Aux. Auxiliary script
  Accessible without login Plain text file form.mvc.php Aux. Auxiliary script
  Accessible without login Plain text file index.mvc.php Aux. Auxiliary script
  Accessible without login Plain text file new.mvc.php Aux. Auxiliary script
  Accessible without login Plain text file show.mvc.php Aux. Auxiliary script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:95
This week:27
All time:9,855
This week:3Up