I wanted to create a simple PHP framework with easy Request
and Response
access, automated Jade template parsing and LESS stylesheet generating. I tried to adapt some of the routing syntax of Express.js for php-kickstart route definition.
For handling new routes you need a Router
with a new Request
and Response
, all access to needed functions is later handled through those response and request objects.
<?php
$Router = new Router(new Request(), new Response());
$Router->get('/')->bind('General', 'home');
$Router->get('/download/:file/:type')->bind('General', 'download');
Create a custom handle in handles/
with classname General
and both methods home
and download
like handles/General.class.php
:
<?php
class General {
public function home(&$req, &$res) {
$res->render('home');
}
public function download(&$req, &$res) {
$res->assign('file', $req->param('file'));
$res->assign('type', $req->param('type'));
$res->render('download');
}
}
The response handler will search for templates in views/
matching the name by adding .jade
, .mustache
or any other registered template engine as file extension.
!!! 5
html
head
meta(http-equiv='content-type', content='text/html; charset=utf-8')
title php–kickstart
body
p Downloading #{file}
| as #{type}
p Downloading #{file} as #{type}