hfw / site
Minimal MVC I/O
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/hfw/site
Requires
- php: ^8.1
- ext-fileinfo: *
This package is auto-updated.
Last update: 2025-10-08 12:00:25 UTC
README
Route requests without overhead and respond as you like.
When you just need an small MVC to do a thing.
Documentation: https://hfw.github.io/site
composer require hfw/site
Web I/O
index.php
<?php include 'vendor/autoload.php'; use Helix\Site; use Helix\Site\Response\View; $site = new Site; // "GET /" $site->get('/', fn() => 'Hello World'); // "GET /foo/123" (regex) $site->get('#^/foo/(?<id>[0-9]+)$#', function(array $path, Site $site) { return new View($site, 'view/foo.phtml', [ 'id' => (int)$path['id'] ]); });
view/foo.phtml
<?php /** * @var Helix\Site\Response\View $this * @var int $id */ echo $id;
Under the Hood
- The
Siteconstructor takes care of general environment setup, including error handling and logging. - If no routes matched, a
404or405error is rendered. - Each HTTP error code can have its own template. A generic template is used as a fallback.
Views
View instances merely include their templates (.phtml files).
Within the scope of those files, $this refers to
the View instance itself. Any data given to the view is converted to variables via extract() in the
same scope as the template inclusion.
By convention, templates should be stored in the view directory in the document root.
nginx config
server {
# ... server config ...
location / {
# ... fastcgi config ...
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
}
}