PHP Web Framework Flight

Flight PHP App with MVC + MariaDB
Flight PHP App with MVC + MariaDB

Live stream set for 2025-08-04 at 14:00:00 Eastern

Ask questions in the live chat about any programming or lifestyle topic.

This livestream will be on YouTube or you can watch below.

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.

About Edward

Edward is a software engineer, web developer, and author dedicated to helping people achieve their personal and professional goals through actionable advice and real-world tools.

As the author of impactful books including Learning JavaScript, Learning Python, Learning PHP, Mastering Blender Python API, and fiction The Algorithmic Serpent, Edward writes with a focus on personal growth, entrepreneurship, and practical success strategies. His work is designed to guide, motivate, and empower.

In addition to writing, Edward offers professional "full-stack development," "database design," "1-on-1 tutoring," "consulting sessions,", tailored to help you take the next step. Whether you are launching a business, developing a brand, or leveling up your mindset, Edward will be there to support you.

Edward also offers online courses designed to deepen your learning and accelerate your progress. Explore the programming on languages like JavaScript, Python and PHP to find the perfect fit for your journey.

📚 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.
🎓 Ready to Learn? – Check out his Online Courses to turn your ideas into results.

Leave a Reply

Your email address will not be published. Required fields are marked *