Route requests without overhead and respond as you like.

Documentation: https://hfw.github.io/site

composer require hfw/site

Web I/O

<tt>index.php</tt>

<?php
include 'vendor/autoload.php';
$site = new Site;
// "GET /"
$site->get('/', fn() => 'Hello World');
// "GET /foo/123" (regex)
$site->get('#^/foo/(?<id>[0-9]+)$#', function(array $path) {
return new View('view/foo.phtml', [
'id' => (int)$path['id']
]);
});

<tt>view/foo.phtml</tt>

<?php
echo $id;

Under the Hood

  • The Site constructor takes care of general environment setup, including error handling and logging.
  • If no routes matched, a 404 or 405 error 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. Data can also be accessed via ArrayAccess.

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;
}
}
Helix\Site
Routing and error handling.
Definition: Site.php:16
Helix\Site\View
Renders a template with data.
Definition: View.php:11