The GalaxyMVC guide

Start with
a request.

Run the framework locally, then follow the PHP from the front controller to the rendered page.

01 / Get started

Run it on your machine.

Use PHP 8.4.27+ or 8.5.12+ in those branches, Composer, and pdo_sqlite. In a fresh checkout:

git clone https://github.com/ZachariahAyers/GalaxyMVC.git
cd GalaxyMVC
composer install
composer setup
php -S localhost:8000 -t public public/index.php

Open http://localhost:8000. The setup command creates and seeds the sample database. Running it again replaces the sample posts.

02 / Routing

A URL names an action.

/home/about resolves to Home::about(). The router uses reflection to check that the action is public, non-static, and accepts the supplied number of arguments. An unmatched route returns HTTP 404.

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

That is the action serving this guide. Keep controller helpers protected or private; public methods are routable.

Read Router.php ↗

03 / Data

Write SQL. Bind the values.

The database wrapper prepares each statement and binds values with their PDO types. Use positional or named parameters.

$post = $this->db->first(
    'SELECT id, title FROM posts WHERE id = :id',
    ['id' => 1],
);

select() returns rows, first() returns one row or null, and execute() returns the affected row count. Set DB_DSN, DB_USER, and DB_PASSWORD for your database.

Read Database.php ↗

04 / Views

Return HTML from PHP.

render() passes data to a template in app/views and wraps it in the shared layout. Escape values when writing them into HTML.

<h1><?= htmlspecialchars($title) ?></h1>

Use $base for internal links so the same application works at the domain root or under a path such as this demo’s /opensource/galaxymvc.

Read View.php ↗

05 / Development

Check the whole framework.

composer check

Runs PHP syntax checks, PSR-12 formatting checks, PHPStan at level 10, and PHPUnit. The full architecture notes live with the source.

Read the architecture ↗