webglue / webglue
Framework in one file
dev-master
2013-05-01 17:20 UTC
Requires
- pimple/pimple: v1.0.1
- symfony/http-foundation: v2.1.7
This package is not auto-updated.
Last update: 2024-05-05 01:22:46 UTC
README
WebGlue is a tiny web framework. Actually it's nothing more than some glue between the Symfony HttpFoundation Request and Response object, and a very simple router. I find it helps me a lot for quick prototyping and small projects.
#Usage
Very simple:
- Instantiate WebGlue
- Add services to instance using array notation (optional)
- Add routes using following syntax
$app-><method>(<route>, <callback>);
- Your callback will get 3 arguments passed to it: the WebGlue instance, a request object, a response object
- Modify the response to your needs. You don't need to return it.
#Examples
##Hello Willem
$app = new WebGlue; // for routes accepting POST, use $app->post, etc. $app->get('/', function($app, $request, $response){ $response->setContent('hello world'); }); $app->get('/greet/{name:string}', function($app, $request, $response){ $name = $request->attributes->get('name'); $response->setContent('hello ' . $name); }); $app->run();
##Add services
$app = new WebGlue; // add the excellent Twig templating engine $app['twig'] = new Twig_Environment(new Twig_Loader_Filesystem(__DIR__.'/templates')); $app->get('/', function($app, $request, $response){ $response->setContent(app['twig']->render('hello_world.html.twig')); });
##Use composer
Only master for now...
{ "require" : { "webglue/webglue": "dev-master" } }
and
include __DIR__.'/vendor/autoload.php';