Created
April 10, 2013 21:00
-
-
Save Gazer/5358399 to your computer and use it in GitHub Desktop.
Refactoring a SlimFramework-based app for fun & profit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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('/'); | |
}); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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('/'); | |
}); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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