Skip to content

Instantly share code, notes, and snippets.

@Gazer
Created April 10, 2013 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gazer/5358399 to your computer and use it in GitHub Desktop.
Save Gazer/5358399 to your computer and use it in GitHub Desktop.
Refactoring a SlimFramework-based app for fun & profit
<?php
get('/', function () {
$contacts = ORM::for_table('contact')->find_many();
render('home.php', array('contacts' => $contacts));
});
get('/contacts/new', function () {
render('contacts/form.php', array(
'contact' => ORM::for_table('contact')->create(),
"title" => "Nuevo Contacto",
'url' => "/contacts")
);
});
post('/contacts', function () {
$contact = ORM::for_table('contact')->create();
/* ... */
redirect('/');
});
?>
<?php
$app->get('/', function () use ($app) {
$contacts = ORM::for_table('contact')->find_many();
$app->render('home.php', array('contacts' => $contacts));
});
$app->get('/contacts/new', function () use ($app) {
$app->render('contacts/form.php', array(
'contact' => ORM::for_table('contact')->create(),
"title" => "Nuevo Contacto",
'url' => "/contacts")
);
});
$app->post('/contacts', function () use ($app) {
$contact = ORM::for_table('contact')->create();
/* ... */
$app->response()->redirect('/');
});
?>
<?php
function render($template, $config) {
\Slim\Slim::getInstance()->render($template, $config);
}
function get($route, $callback) {
\Slim\Slim::getInstance()->get($route, $callback);
}
function post($route, $callback) {
\Slim\Slim::getInstance()->post($route, $callback);
}
function put($route, $callback) {
\Slim\Slim::getInstance()->put($route, $callback);
}
function delete($route, $callback) {
\Slim\Slim::getInstance()->delete($route, $callback);
}
function redirect($path) {
\Slim\Slim::getInstance()->response()->redirect($path);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment