register('pdo', 'PDO', array('mysql:host=localhost;dbname=test', 'root', '', array( PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ) ) ); $app->register('fenom', 'Fenom::factory', array( 'resource/views', 'resource/cache', array( 'auto_reload' => true ) ) ); $app->route('/', function() use($app) { $request = $app->request(); if ($request->data->send && !empty($request->data->code)) { $hash = substr(str_shuffle(uniqid('qwertyuiopasdfghjklzxcvbnm')), 0, 9); $query = $app->pdo() ->prepare("insert into `codes` (`code`, `hash`, `time`) values (?, ?, now())"); $query->execute(array($request->data->code, $hash)); $app->redirect('/' . $hash); } $app->fenom()->display('home.phtml'); }); $app->route('/@hash:[a-z0-9]{9}', function($hash) use($app) { $query = $app->pdo()->prepare("select * from `codes` where `hash` = ?"); $query->execute(array($hash)); $code = $query->fetch(); if ($code) { $app->fenom()->display('code.phtml', array( 'code' => $code )); } else $app->redirect('/'); }); $app->start();