Skip to content

Instantly share code, notes, and snippets.

@dmouse
Created March 4, 2013 03:33
Show Gist options
  • Save dmouse/5079709 to your computer and use it in GitHub Desktop.
Save dmouse/5079709 to your computer and use it in GitHub Desktop.
Ejemplo de uso de Silex
// web/index_dev.php
require_once __DIR__.'/../vendor/autoload.php';
//inicio de la aplicación
$app = new Silex\Application();
//Index
$app->match('/', function () {
...
})
->bind('home'); // alias para uso interno
// mipage.com/contact
$app->match('/contact', function () {
...
});
// acceso a /contact_send solo por metodo POST
$app->match('/contact_send', function () {
...
})
->method('POST');
//rutas dinamicas
$app->get('/blog/{id}', function ($id) {
...
});
// multiple paso de variables
$app->get('/blog/{postId}/{commentId}', function ($commentId, $postId) {
...
});
// manejo de json
$app->get('/my_porn/{id}', function ($id) use ($app) {
$porn = getPorn($id);
if (!$porn) {
$error = array('message' => 'Noooooooooooooo');
return $app->json($error, 404);
}
return $app->json($porn);
});
// para uso en desarrollo
$app['debug'] = true;
$app->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment