oito/php-micro

Oito PHP microframework

Installs: 10

Dependents: 1

Stars: 3

Watchers: 1

Language: PHP

v1.0.0 2014-03-06 01:57 UTC

README

Uses the libraries

Usage

use \Oito\Micro\Application as App;

// passing a config array to the Application constructor is optional
$config = [
    'session' => [
        'name' => 'MYSESSIONID'
    ]
];

$app = new \Oito\Micro\Application($config);

// you can also use:
// - POST
// - PUT
// - DELETE
// - ANY (this will match any request method)
$app->get('/', function(App $app) {
    // inside a callable, $this also points to the Application instance
    return $app->html('This is the / route');
});

$app->get('/hello/[:name]', function(App $app, $name) {
    // the 1st parameter is always the Application instance
    // route parameters are passed in alphabetical order, starting from the 2nd parameter
    return $app->html('Hello ' . $name);
});

$app->event()->on('run.before', function(App $app, $route, $callable, $params) {
    // $app maps to the Application instance
    // $route maps to the current matched route
    // $callable maps to the current route callable
    // $params maps to the current route parameters
});

$app->event()->on('run.after', function(App $app, $route, $callable, $params, $response) {
    // $app maps to the Application instance
    // $route maps to the current matched route
    // $callable maps to the current route callable
    // $params maps to the current route parameters
    // $response maps to the response returned from the route callable
});

// if you want View rendering, simply add Twig or Symfony Templating plugin for Oito PHP Microframework to your composer.json and configure it
$app->addPlugin(new \Oito\Micro\Plugin\Twig());

$app->run();