PHP Web Framework Flight

Flight PHP App with MVC + MariaDB
Revised 3 min, 28 sec read

Getting Started with Flight PHP: MVC and MariaDB Integration Made Easy

Welcome to your first Flight PHP tutorial! Flight is a fast, simple, and extensible micro-framework for PHP that enables you to build web apps and APIs quickly—perfect for beginners and experienced developers alike.

The framework has been actively revived, with community contributions restoring features like route groups, middleware, and a simple database wrapper while maintaining compatibility with v2 apps. See the official docs at docs.flightphp.com and source code at github.com/flightphp/core.

In this beginner’s guide, we will:

  • Install Flight PHP v3.17.0 via Composer
  • Set up a minimal MVC app
  • Connect to a MariaDB database and render a list of users

1. Installing Flight PHP v3.17.0 Using Composer

In your project directory, run the following commands:

composer require flightphp/core:3.17.0

This installs version 3.17.0, released July 20, 2025. PHP 7.4+ is required.

2. Creating a Simple MVC Structure

Use the following structure for your application:

project/
│-- controllers/
│    └-- HomeController.php
│-- models/
│    └-- UserModel.php
│-- views/
│    └-- users.php
└-- index.php

Routing & Bootstrapping (index.php)

<?php
require 'vendor/autoload.php';
require 'controllers/HomeController.php';
require 'models/UserModel.php';

Flight::set('flight.views.path', 'views');
Flight::route('/', [new HomeController(), 'index']);
Flight::start();

3. Model Layer (models/UserModel.php)

<?php
class UserModel {
    private PDO $db;
    public function __construct(PDO $pdo) {
        $this->db = $pdo;
    }
    public function getAllUsers(): array {
        $stmt = $this->db->query("SELECT * FROM users");
        return $stmt->fetchAll(PDO::FETCH_ASSOC);
    }
}

4. Controller Layer (controllers/HomeController.php)

<?php
class HomeController {
    public function index() {
        $pdo = new PDO('mysql:host=localhost;dbname=testdb;charset=utf8', 'username', 'password', [
            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
        ]);
        $model = new UserModel($pdo);
        $users = $model->getAllUsers();
        Flight::render('users', ['users' => $users]);
    }
}

5. View Layer (views/users.php)

<!DOCTYPE html>
<html>
<head><meta charset="utf-8"><title>User List</title></head>
<body>
<h1>User List</h1>
<ul>
<?php foreach ($users as $user): ?>
  <li><?= htmlspecialchars($user['name']) ?> (<?= htmlspecialchars($user['email']) ?>)</li>
<?php endforeach; ?>
</ul>
</body>
</html>

Recommended Database Schema

CREATE TABLE users (
  id INT AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(100),
  email VARCHAR(100)
);

INSERT INTO users (name, email) VALUES
('Alice Smith', 'alice@example.com'),
('Bob Jones', 'bob@example.com');

MVC Support Overview

While Flight PHP does not enforce a full MVC directory structure, it fully supports MVC-style routing and templating through Flight::route() and Flight::render(). You can organize your application easily using these features. Learn more in the Flight PHP Docs.

📷 Screenshots & Screencast

Flight Dependencies
Command Line Installation Of Flight Web Framework

Flight User Router
Gnome Text Editor Displaying Router App File

Flight User Model
Gnome Text Editor Displaying Custom User Model

Flight User Controller
Gnome Text Editor Displaying Custom User Controller

Flight User View
Gnome Text Editor Displaying Custom User View

Flight People Result
Web Browser Displaying Custom People Route Result

Flight Custom View Records In Web Browser

📚 Further Resources & Services

Conclusion

Flight PHP v3.17.0 is a lightweight and modern micro-framework that gives you everything you need to build efficient MVC applications. With support for MariaDB and clean routing, it’s a perfect choice for new developers and rapid prototyping.

Need help with forms, API development, or custom routing? Let me know—I offer professional support and tutorials to help you succeed.

🚀 Recommended Resources


Disclosure: Some of the links above are referral links. I may earn a commission if you make a purchase at no extra cost to you.

About Edward

Edward is a software engineer, author, and designer dedicated to providing the actionable blueprints and real-world tools needed to navigate a shifting economic landscape.

With a provocative focus on the evolution of technology—boldly declaring that “programming is dead”—Edward’s latest work, The Recession Business Blueprint, serves as a strategic guide for modern entrepreneurship. His bibliography also includes Mastering Blender Python API and The Algorithmic Serpent.

Beyond the page, Edward produces open-source tool review videos and provides practical resources for the “build it yourself” movement.

📚 Explore His Books – Visit the Book Shop to grab your copies today.

💼 Need Support? – Learn more about Services and the ways to benefit from his expertise.

🔨 Build it Yourself – Download Free Plans for Backyard Structures, Small Living, and Woodworking.

Comments

One response to “PHP Web Framework Flight”

  1. n0nag0n Avatar

    Thanks for doing the write up! I added your article to the media page on the Flight docs site. https://docs.flightphp.com/en/v3/media