A small framework for PHPModel / View / Controller

GalaxyMVC

PHP2ShellPatched

Small by design.
PHP all the
way down.

A router, a PDO data layer, and plain PHP views. Enough structure to build with. Little enough to read in full.

PHP 8.4.27+ / 8.5.12+Data Prepared PDO queriesViews Plain PHPLicense Apache 2.0

01 / In practice

A page with
nothing to hide.

These posts come from the demo’s SQLite database. Open the source below to see the controller, model, and view that put them here.

Rendered by GalaxyMVCGET /home/index
#1

Routing

The router checks with reflection that a path names a public action before anything runs.

#2

Prepared statements

Every value is bound with a PDO type taken from its PHP type, never joined into SQL.

#3

Views

Templates are plain PHP, escaped with htmlspecialchars and rendered inside one layout.

View sourceapp/Controllers/Home.php
<?php

declare(strict_types=1);

namespace App\Controllers;

use App\Core\Controller;
use App\Models\Post;
use RuntimeException;

final class Home extends Controller
{
    public function index(): string
    {
        return $this->render('home/index', [
            'title' => 'GalaxyMVC',
            'posts' => (new Post($this->db))->all(),
            'sources' => $this->source(),
        ]);
    }

    public function about(): string
    {
        return $this->render('home/about', ['title' => 'Guide']);
    }

    /** @return array<string, string> */
    private function source(): array
    {
        // Only these public demo files can be displayed; no request value becomes a file path.
        $sources = [];
        foreach (['Controllers/Home.php', 'Models/Post.php', 'views/home/posts.php'] as $path) {
            $contents = file_get_contents(dirname(__DIR__) . '/' . $path);
            if ($contents === false) {
                throw new RuntimeException('Demo source is unavailable.');
            }
            $sources['app/' . $path] = $contents;
        }

        return $sources;
    }
}
Open on GitHub
View sourceapp/Models/Post.php
<?php

declare(strict_types=1);

namespace App\Models;

use App\Core\Database;

final class Post
{
    public function __construct(private readonly Database $db)
    {
    }

    /**
     * @return list<array<string, mixed>>
     */
    public function all(): array
    {
        return $this->db->select('SELECT id, title, content FROM posts ORDER BY id');
    }
}
Open on GitHub
View sourceapp/views/home/posts.php
<?php

declare(strict_types=1);

/** @var list<array<string, mixed>> $posts */
?>
<div class="query-results" aria-label="Records rendered from the database">
    <?php foreach ($posts as $post) : ?>
        <article class="result-row">
            <span class="row-number">#<?= htmlspecialchars((string) $post['id']) ?></span>
            <h3><?= htmlspecialchars((string) $post['title']) ?></h3>
            <p><?= htmlspecialchars((string) $post['content']) ?></p>
        </article>
    <?php endforeach; ?>
    <?php if ($posts === []) : ?>
        <p class="empty-state">No posts in the database. Run <code>composer setup</code> in a fresh local checkout to load the sample records.</p>
    <?php endif; ?>
</div>
Open on GitHub

02 / Make it yours

Your next request
starts here

Install it. Follow a request.
Build from there.

Read the guide