Home

Awesome

Hackwork

Layout-based PHP micro-framework for full-stack HTML5 sites

Hackwork is a layout-based PHP micro-framework made for HTML5 sites. You can also make HTML4 sites with Hackwork, don't worry.

Minimal required PHP version is 5.6.0. Hackwork may work on older PHP versions, although they aren't supported officially.

Table of contents

Example

<?php

require_once 'core/hackwork.php';
layout('default', 'home');

Getting started

  1. Clone the repository.
  2. Modify layouts for your pages.
  3. Fill data/ and assets/.
  4. Test your site locally to see does everything works well.

Directory structure

Hackwork projects should have a simple directory structure.

.
├── assets/
│   ├── css/
│   ├── fonts/
│   ├── img/
│   ├── js/
│   ├── ...
├── core/
│   ├── helpers/
│   ├── hackwork.php
├── data/
│   ├── ...
└── layouts/
    └── .../
        ├── footer.php
        ├── header.php
        ├── i.functions.php
        ├── i.variables.php
        └── ...

Core

Constants

There are path and configuration constants.

Paths

You should omit trailing slashes in path constants.

Environment

There is an environment constant, ENV. Its values are:

By default it's development. You should change it if your site is for production.

Helpers

Hackwork has some helpers, e.g. to make layout. All of them are automatically imported to core/hackwork.php.

Configuration

Server configuration is in the core/helpers/config.php. You should edit it to adjust the configuration.

Compression

Pages loads faster with compression, so Hackwork enables it by default.

Default charset

There is a charset definition to ensure right charset is used everywhere. Hackwork sets default charset to UTF-8.

Default timezone

PHP requires default timezone for proper working of time functions. Hackwork sets default timezone to UTC.

Layouts

Hackwork uses layouts as page generating model.

Layout basics

Layouts are like page templates. You don't need to learn new templating language as Hackwork uses pure PHP syntax.

Layout sections

Other layout files

Use i. prefix for layout files that should be included. Core i. files are:

You can create additional i. files, e.g. for constants and classes.

Layout generator

To generate layout, use layout($layout, $data, $page_title) function.

Default layout

Default layout is just a template. It lies within layouts/default/.

Default layout variables

Default layout variables are in layouts/default/i.variables.php.

Default layout base variables
Default layout meta variables
Default layout assets variables
Default layout copyright variables

Default layout functions

Default layout functions are in layouts/default/i.functions.php.

Default layout generation functions
Default layout basic functions

New layout

To make a new layout, create a new directory within layouts/ and follow layout basics. You can use default layout as template.

HTTP

Hackwork caches HTTP properties and header messages for easier HTTP control.

HTTP properties

HTTP headers

$header is an array of default HTTP header messages. You can use headers with $header[<status-number>].

Errors

Hackwork has a simple error thrower.

Exit status codes

Error thrower

To throw an error, set consistent headers and terminate script, use throwerr($header_status, $exit_status, $msg, $header_msg).

Contributing

Want to contribute? Check out contributing guide.

License

MIT © Zlatan Vasović